php Laravel 5.3 db:seed 命令根本不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39521913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.3 db:seed command simply doesn't work
提问by Peter
I do everything by-the-book:
我做所有的事情:
Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error)
run
php artisan make:auth
create migrations for a new table `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(); });
Then I run
php artisan migrate
Then I define a new seed
php artisan make:seeder QuotationsTableSeeder
安装了新的 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
The complete content of the file, after I add a simple insert:
文件的完整内容,在我添加一个简单的插入之后:
<?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),
]);
}
}
- Then I run
php artisan db:seed
- 然后我跑
php artisan db:seed
problem
问题
it simply doesn't work. No feedback presented, no errors in log file. The probem persists in both my local environment (Win7, newest WAMP server) and my Digital Ocean VPS powered by Ubuntu 16.04. All the above steps I took in several separate apps - for no result. Also under Laragon 2.0.5 server.
它根本不起作用。没有反馈,日志文件中没有错误。该探测器在我的本地环境(Win7,最新的 WAMP 服务器)和我的由 Ubuntu 16.04 提供支持的 Digital Ocean VPS 中都存在。我在几个单独的应用程序中采取的所有上述步骤 - 没有结果。同样在 Laragon 2.0.5 服务器下。
what I have tried
我试过的
php artisan optimize
as suggested here.
php artisan optimize
正如这里所建议的。
composer dump-autoload
i php artisan clear-compiled
also have brought no results
composer dump-autoload
我php artisan clear-compiled
也没有带来任何结果
I also tried to seed just following the official docs example - failed.
我还尝试按照官方文档示例进行播种 - 失败。
I added use DB;
to the seed file - still no result.
我添加use DB;
到种子文件 - 仍然没有结果。
to do
去做
help!!! How come they don't work?
帮助!!!他们怎么不工作?
回答by Rafael Berro
Are you calling your seeder inside the DatabaseSeeder
class? This way:
你在DatabaseSeeder
课堂上打电话给你的播种机吗?这边走:
database/seeds/DatabaseSeeder.php
数据库/种子/DatabaseSeeder.php
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(QuotationTableSeeder::class);
}
}
Or, add the --class
option when using the php artisan db:seed
command, this way:
或者,--class
在使用php artisan db:seed
命令时添加选项,如下所示:
php artisan db:seed --class="QuotationTableSeeder"
After creating or removing your seeders, don't forget to run the following command:
创建或删除播种机后,不要忘记运行以下命令:
composer dump-autoload
回答by petermafia
If anybody else is having issues with migrating AND seeding at the same time, please try
如果其他人同时在迁移和播种方面遇到问题,请尝试
php artisan migrate:fresh --seed
Worked for me..
为我工作..