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

问题描述 投票:0回答:3

我一切都按规矩办事:

  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-autoload
php artisan clear-compiled
也没有带来任何结果

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

我将

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

要做

救命!!!为什么他们不起作用?

php laravel seeding laravel-5.3 laravel-seeding
3个回答
81
投票

您是否在

DatabaseSeeder
班级中给您的播种者打电话?这样:

数据库/seeds/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

0
投票

注意: 请在开发环境和/或一次性数据库上谨慎使用

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

php artisan migrate:fresh --seed

为我工作..


0
投票

就我而言, (玛丽亚数据库) 检查你的自动提交。 mariaDB/data/my.ini <= here turn on your autocommit

© www.soinside.com 2019 - 2024. All rights reserved.