在 Laravel 5 中使用 --force 在生产中使用播种机进行迁移时,数据库陷入困境

Yev*_*yev 2 laravel laravel-seeding laravel-migrations

在 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']);
}
Run Code Online (Sandbox Code Playgroud)

我这样称呼它:

$ php artisan migrate --force
Run Code Online (Sandbox Code Playgroud)

我的 .env

#APP_ENV=local

APP_DEBUG=false
Run Code Online (Sandbox Code Playgroud)

数据库种子。

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

已测试 Laravel 5.6

Jee*_*usu 5

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

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

$ php artisan migrate --force

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

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

  • `'--force' =&gt; true,` 确实有帮助。谢谢你。 (3认同)