我通过书来做所有事情:
安装了新的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 optimize
如这里建议的。
composer dump-autoload
我php artisan clear-compiled
也没有带来任何结果
我还尝试遵循官方docs示例进行播种-失败。
我添加use DB;
到种子文件-仍然没有结果。
救命!!!他们怎么不工作?
你在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] 删除。
我来说两句