我做任何事都按部就类:
安装了新的 Laravel 5.3.9 应用(我所有的非新应用都会产生相同的错误)
运行
php artisan make:auth
为新表创建迁移 `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(); });
然后我运行
php artisan migrate
然后我定义一个新的种子
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),
]);
}
}
- 然后我运行
php artisan db:seed
问题
它根本不起作用。没有反馈,日志文件中没有错误。 探针在我的本地环境中都存在(Win7,最新的 WAMP 服务器) 和我的由 Ubuntu 16.04 驱动的 Digital Ocean VPS。 我在几个单独的应用程序中采取了上述所有步骤 - 没有结果。也在 Laragon 2.0.5 服务器下。
我尝试过的
php artisan 优化
as suggested here .
composer dump-autoload
i php artisan clear-compiled
也没有带来任何结果
我也尝试按照官方文档示例进行播种 - 失败了。
我在种子文件中添加了 use DB;
- 仍然没有结果。
要做的事情
帮助!!!为什么它们不起作用?
最佳答案
您是在 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 - Laravel 5.3 数据库 :seed command simply doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39521913/