Laravel 5.3 db:seed命令根本不起作用 [英] Laravel 5.3 db:seed command simply doesn't work

查看:346
本文介绍了Laravel 5.3 db:seed命令根本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在书上做所有事情:

  1. 已安装新的Laravel 5.3.9应用程序(我所有的非新鲜应用程序都产生相同的错误)

  1. Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error)

运行php artisan make:auth

为新表创建迁移 `php artisan make:migration create_quotations_table --create = quotations

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();
});

  • 然后我运行php artisan migrate

    然后我定义一个新种子php artisan make:seeder QuotationsTableSeeder

    Then I define a new seed 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),
    
        ]);
    }
    }
    

    1. 然后我运行php artisan db:seed

    问题

    它根本不起作用.没有反馈,日志文件中没有错误. 该探针在我的两个本地环境中都存在(Win7,最新的WAMP服务器) 和由Ubuntu 16.04提供支持的Digital Ocean VPS. 以上所有步骤都是我在几个单独的应用中执行的-没有结果.同样在Laragon 2.0.5服务器下.

    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.

    php artisan optimize 如此处建议.

    composer dump-autoloadphp artisan clear-compiled也没有结果

    我也尝试遵循官方docs示例进行播种-失败.

    I also tried to seed just following the official docs example - failed.

    我在种子文件中添加了use DB;-仍然没有结果.

    I added use DB; to the seed file - still no result.

    帮助!!!他们怎么不起作用?

    help!!! How come they don't work?

    推荐答案

    您是否在DatabaseSeeder类中调用播种机?这样:

    Are you calling your seeder inside the DatabaseSeeder class? This way:

    数据库/种子/DatabaseSeeder.php

    class DatabaseSeeder extends Seeder
    {
        /**
         * Run the database seeds.
         *
         * @return void
         */
        public function run()
        {
            $this->call(QuotationTableSeeder::class);
        }
    }
    

    或者,使用php artisan db:seed命令时,通过以下方式添加--class选项:

    Or, add the --class option when using the php artisan db:seed command, this way:

    php artisan db:seed --class="QuotationTableSeeder"
    

    创建或删除播种器后,请不要忘记运行以下命令:

    After creating or removing your seeders, don't forget to run the following command:

    composer dump-autoload
    

    这篇关于Laravel 5.3 db:seed命令根本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆