Home > Blockchain >  Php artisan migrate doesn't work in laravel project
Php artisan migrate doesn't work in laravel project

Time:01-19

I created a new laravel project, I set the db data in .env file and I've created 2 new tables but when i run php artisan migrate doesn't return me nothing, it continue to load a migration endlessy.

I'm sure that the db credential i .env are correct, I'm using phpmyadmin and as host in .env i wrote mysql

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->integer('matricola');
            $table->string('nome');
            $table->string('cognome');
            $table->string('luogo_nascita');
            $table->date('data_nascita');
            $table->string('incarico');
            $table->string('indirizzo');
            $table->integer('cap');
            $table->string('città');
            $table->string('provincia');
            $table->string('nazionalità');
            $table->string('codice_fiscale')->unique();
            $table->string('telefono')->unique();
            $table->string('email_personale')->unique();
            $table->string('email_aziendale')->unique();
            $table->string('banca');
            $table->string('iban')->unique();
            $table->integer('ore_contratto');
            $table->integer('giorni_ferie_anno');
            $table->integer('ore_permesso_annuali');
            $table->string('password');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
};

CodePudding user response:

I think you creatd migration manually if that's the case then I would recommend to use artisan commands to generate migration like

php artisan make:migration Create_users_table

this will create a migration template which will look like this

 <?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('users');
}
}

CodePudding user response:

It sounds like there may be an issue with the migration file you've created. In Laravel, migrations should be created using the command php artisan make:migration create_users_table rather than creating a new class file manually.

In this migration file there are some errors:

Instead of return statement, you need to use class statement, like this:

class CreateUsersTable extends Migration

Also, make sure that the database connection settings in your .env file are correct and that the database specified in the connection settings actually exists on your server. After that, you could try running the command php artisan config:clear and then run the migration command again.

If you still have problems, you can check the logs folder and see if you have any error message in the logs.

  • Related