Laravel 5.3 db:seed command simply doesn't work
Asked Answered
P

3

28

I do everything by-the-book:

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

  2. run php artisan make:auth

  3. 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();
    });
    
  4. Then I run php artisan migrate

  5. 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. Then I run 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.

what I have tried

php artisan optimize as suggested here.

composer dump-autoload i php artisan clear-compiled also have brought no results

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

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

to do

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

Pent answered 15/9, 2016 at 23:46 Comment(1)
in my case when module in subfolders and want to run in directly without running other seeder php artisan db:seed --class=WM\Common\Seeder\SmsStatusSeederHastie
D
81

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

database/seeds/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:

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

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

composer dump-autoload
Deyo answered 16/9, 2016 at 0:29 Comment(6)
for me it only works with the --class option, even when I added it to the public run function. Any ideas why?Vip
Glad you answered this, first time the docs have lead me astray.Hexachlorophene
Glad I could help you.Deyo
You have to add the Seeder you created to DatabaseSeeder $this->call(QuotationTableSeeder::class); after this, you can just call php artisan db:seedLegalism
It's 7.x and this is not in the official documentation.Heparin
why is this a step I need to takeSuint
A
0

NB: Please use with caution on DEV ENVIRONMENT and/or DISPOSABLE DATABASES ONLY

If anybody else is having issues with migrating AND seeding at the same time, please try

php artisan migrate:fresh --seed

Worked for me..

Ankylosis answered 6/12, 2018 at 14:48 Comment(1)
I will not recommend this since this command will: drop all tables from the database and then execute the migrate command. This can be catastrophic for some!Babara
S
0

In my case, (mariaDB) Check your auto commit. mariaDB/data/my.ini <= here Turn on your autocommit

Sonatina answered 13/11, 2023 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.