Php Laravel5.3db:seed命令根本不';行不通

Php Laravel5.3db:seed命令根本不';行不通,php,laravel,seeding,laravel-5.3,laravel-seeding,Php,Laravel,Seeding,Laravel 5.3,Laravel Seeding,我做每件事都是按部就班的: 已安装fresh Laravel 5.3.9应用程序(我的所有非fresh应用程序都会产生相同的错误) 运行php artisan make:auth 为新表创建迁移 `php artisan make:migration create_quotes_table--create=quotes Schema::create('quotations', function (Blueprint $table) { $table->increments('id'

我做每件事都是按部就班的:

  • 已安装fresh Laravel 5.3.9应用程序(我的所有非fresh应用程序都会产生相同的错误)

  • 运行php artisan make:auth

  • 为新表创建迁移 `php artisan make:migration create_quotes_table--create=quotes

    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();
    });
    
  • 然后我运行
    php artisan migrate

  • 然后我定义了一个新的seed
    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),
    
        ]);
    }
    }
    

    您是否在
    DatabaseSeeder
    类中调用您的播种机?这样:

    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
    
    注意: 请仅在开发环境和/或一次性数据库上谨慎使用

    如果其他任何人同时在迁移和种子设定方面遇到问题,请尝试

    php artisan migrate:fresh --seed
    

    为我工作。

    对我来说,它只与
    --class
    选项一起工作,即使我将其添加到公共运行函数中。知道为什么吗?很高兴你回答了这个问题,第一次文档让我误入歧途。很高兴我能帮助你。谢谢你Rafael Berro先生。它是7.x,官方文档中没有。我不建议这样做,因为这个命令将:
    从数据库中删除所有表,然后执行migrate命令。这对一些人来说可能是灾难性的!在我的例子中,当模块位于子文件夹中,并且想要直接运行而不运行其他种子机php artisan db:seed--class=WM\Common\seeder\smsstatusseed时