Search code examples
laravellaravel-migrationslaravel-seeding

Database gets stuck in migration with seeder on production with --force in Laravel 5


Database gets stuck in migration with seeder on production with --force in Laravel. Same effect I have on Laravel Homestead and EC2 AWS running Amazone linux. No messages in laravel.log.

It just never ends. If I halt it with <ctrl>+<c>, I see the table created but seeder was not run, the table is empty.

Detalis:

My migration:

public function up()
{
    Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name', 50);
        $table->decimal('price', 8, 2); //up to 999,999.99
    });

    Artisan::call('db:seed', ['--class' => 'ProductsSeeder']);
}

I call it like so:

$ php artisan migrate --force

my .env

#APP_ENV=local

APP_DEBUG=false

the database seeds.

class ProductsSeeder extends Seeder
{
    public function run()
    {
        DB::table('products')->insert([
            'id'                   => 1,
            'name'                 => 'super product',
            'price'                => 999.99,
        ]);
    }

Tested Laravel 5.6


Solution

  • Try including the -vvv flag in your migration command, this will increase the verbosity of any messages, which might uncover the problem.

    --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

    $ php artisan migrate --force

    As for the problem itself, try including the --force flag in your db:seed call, as you have included it in the migration.

    Artisan::call('db:seed', ['--class' => 'ProductsSeeder', '--force' => true,]);