首页 > 解决方案 > 使用 Laravel 5 中的 --force 进行生产时,数据库卡在使用播种机迁移

问题描述

使用 Laravel 中的 --force 进行生产时,数据库在使用播种机迁移时卡住了。我对运行 Amazone linux 的 Laravel Homestead 和 EC2 AWS 的效果相同。laravel.log 中没有消息。

它永远不会结束。如果我用 停止它<ctrl>+<c>,我会看到表已创建但播种器未运行,表为空。

细节:

我的迁移:

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']);
}

我这样称呼它:

$ php artisan migrate --force

我的 .env

#APP_ENV=local

APP_DEBUG=false

数据库种子。

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

测试 Laravel 5.6

标签: laravellaravel-migrationslaravel-seeding

解决方案


尝试-vvv在迁移命令中包含标志,这会增加任何消息的详细程度,这可能会发现问题。

--verbose (-v|vv|vvv) 增加消息的详细程度:1 为正常输出,2 为更详细的输出,3 为调试

$ php artisan migrate --force

至于问题本身,请尝试--force在调用中包含标志db:seed,因为您已将其包含在迁移中。

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


推荐阅读