Laravel 5.3 db:seed 命令根本不起作用

Laravel 5.3 db:seed command simply doesn't work

我做每件事都照章办事:

  1. 安装了新的 Laravel 5.3.9 应用程序(我所有的非新应用程序都产生相同的错误)

  2. 运行 php artisan make:auth

  3. 为新 table 创建迁移 `php artisan make:migration create_quotations_table --create=quotations

    Schema::create('quotations', function (Blueprint $table) {
        $table->increments('id');
    
        $table->string('text');
    
        // my problem persists even with the below two columns commented out
        $table->integer('creator_id')->unsigned()->index('creator_id');
        $table->integer('updater_id')->unsigned()->index('updater_id');
    
        $table->softDeletes();
        $table->timestamps();
    });
    
  4. 那我运行php artisan migrate

  5. 然后我定义一个新的种子php artisan make:seeder QuotationsTableSeeder

文件的完整内容,我添加后简单插入:

<?php

use Illuminate\Database\Seeder;

class QuotationsTableSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    DB::table('quotations')->insert([
        'text' => str_random(10),

    ]);
}
}
  1. 那我运行php artisan db:seed

问题

根本行不通。没有反馈,日志文件中没有错误。 该问题在我的本地环境(Win7,最新的 WAMP 服务器)中都存在 我的数字海洋 VPS 由 Ubuntu 16.04 提供支持。 我在几个单独的应用程序中执行了上述所有步骤 - 但没有结果。同样在 Laragon 2.0.5 服务器下。

我试过的

php artisan optimize as suggested here.

composer dump-autoloadphp artisan clear-compiled也没有结果

我也尝试按照官方文档示例进行播种 - 失败了。

我在种子文件中添加了 use DB; - 仍然没有结果。

要做

求助!!!为什么它们不起作用?

您是在 DatabaseSeeder class 中调用播种器吗?这样:

database/seeds/DatabaseSeeder.php

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(QuotationTableSeeder::class);
    }
}

或者,在使用php artisan db:seed命令时加上--class选项,这样:

php artisan db:seed --class="QuotationTableSeeder"

创建或删除播种机后,请不要忘记运行以下命令:

composer dump-autoload

注意: 请谨慎使用开发环境and/or一次性数据库

如果其他人同时遇到迁移和播种问题,请尝试

php artisan migrate:fresh --seed

对我有用..