Pet*_*ter 19 php seeding laravel laravel-seeding laravel-5.3
我按照书本做了一切:
安装了新的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();
});
Run Code Online (Sandbox Code Playgroud)然后我跑了 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),
]);
}
}
Run Code Online (Sandbox Code Playgroud)
php artisan db:seed它根本不起作用.没有反馈,日志文件中没有错误.探测器在我的本地环境(Win7,最新的WAMP服务器)和由Ubuntu 16.04驱动的数字海洋VPS中都存在.我在几个单独的应用程序中采取了上述所有步骤 - 没有结果.也在Laragon 2.0.5服务器下.
php artisan optimize 如此处所示.
composer dump-autoload我php artisan clear-compiled也没有带来任何结果
我也尝试按照官方文档示例播种 - 失败.
我添加use DB;到种子文件 - 仍然没有结果.
救命!!!他们怎么不工作?
Raf*_*rro 51
你在DatabaseSeeder课堂上叫你的播种机吗?这条路:
数据库/种子/ DatabaseSeeder.php
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(QuotationTableSeeder::class);
}
}
Run Code Online (Sandbox Code Playgroud)
或者,--class在使用php artisan db:seed命令时添加选项,这样:
php artisan db:seed --class="QuotationTableSeeder"
Run Code Online (Sandbox Code Playgroud)
创建或删除播种机后,请不要忘记运行以下命令:
composer dump-autoload
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19996 次 |
| 最近记录: |