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

彼得:

我通过书来做所有事情:

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

  2. php artisan make:auth

  3. 为新表创建迁移`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服务器)和由Ubuntu 16.04提供支持的Digital Ocean VPS中都存在。以上所有步骤都是我在几个单独的应用中执行的-没有结果。同样在Laragon 2.0.5服务器下。

我尝试过的

php artisan optimize 如这里建议的

composer dump-autoloadphp artisan clear-compiled也没有带来任何结果

我还尝试遵循官方docs示例进行播种-失败。

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

去做

救命!!!他们怎么不工作?

拉斐尔·贝罗(Rafael Berro):

你在DatabaseSeeder班上叫播种机吗?这条路:

数据库/种子/DatabaseSeeder.php

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

或者,通过以下--class方式在使用php artisan db:seed命令添加选项

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

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

composer dump-autoload

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章