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
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), ]); } }
php artisan db:seed
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
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.
help!!! How come they don't work?
Laravel Seeding Creating a Seeder To create seeders, you may use the make:seeder Artisan command. All seeders generated will be placed in the database/seeds directory. Generated seeders will contain one method: run . You may insert data into your database in this method.
Writing SeedersA seeder class only contains one method by default: run . This method is called when the db:seed Artisan command is executed. Within the run method, you may insert data into your database however you wish. You may use the query builder to manually insert data or you may use Eloquent model factories.
use Undo Seeder for Laravel. When you install UndoSeeder, the following artisan commands are made available: db:seed-undo Undo seeds in the seeds directory. db:seed-refresh Undo seeds run seeds again.
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
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With