Framework: artisan db:seed does not work and does not print an error, if you want to insert multiple rows with different amount of key-value pairs

Created on 29 Aug 2013  路  13Comments  路  Source: laravel/framework

artisan db:seed does not work and throws no error, if you provide an array like this one. On the command line you just get this message: "Database seeded!"

The bug is not that such an INSERT does not work, but you get NO ERROR MESSAGE. So someone assume that the database-insert does work and searches hours for the problem...

The table structure:

    Schema::create('categories', function(Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('position');
    });

The SEED array:

    $categories = array(
        array(
            'id' => '1',
            'name' => 'Metalle',
        ),
        array(
            'id' => '2',
            'name' => 'Eisen',
            'position' => 2,
        ),
    );

The artisan commands:
php artisan migrate
php artisan db:seed

Most helpful comment

there is no problem , you have to register your seeder in DatabaseSeeder.php inside app/database/seed folder : add this line in DatabaseSeeder.php
$this->call(YourSeeder ::class)

All 13 comments

you are doing something wrong and have given nothing to go on to help you. This belongs on the forums, not a bug. As I have done it many times before and so have a lot of other people.

Well, it actually is a bug but don't expect a fix for this, as it would get messy and an easy solution is to just use the same array structure everywhere (declare the same keys, possibly by using null as the value)

I don't see the bug, doesn't help that the report is just showing some basic array. Because what he shows I am sure I have done before.

Inserts are done in batch when you do this so, short of creating batches based on parameters being identical, this isn't a bug so much as how the Bulk inserts are performed.

Sry, may I did not provide enough information. I will update my first post. Please let me know if something isn't clear to you.

What database are you using out of curiosity? Because MySQL threw an error for me.

I'm using MySQL too.

Behaviour in detail:

[Exception] Invalid parameter number:

    $materialcategories = array(
        array(
            'id' => '1',
            'name' => 'Metalle',
            'position' => 1,
        ),
        array(
            'id' => '2',
            'name' => 'Eisen',
        ),

Database seeded! (Actually NO data was inserted):

    $materialcategories = array(
        array(
            'id' => '1',
            'name' => 'Metalle',
        ),
        array(
            'id' => '2',
            'name' => 'Eisen',
            'position' => 1,
        ),

Yup. It only throws the exception when you've got less items in the arrays that are running later.

Yeah you need to have the same columns in each row.

there is no problem , you have to register your seeder in DatabaseSeeder.php inside app/database/seed folder : add this line in DatabaseSeeder.php
$this->call(YourSeeder ::class)

Actually they haven't any default value for "position" that's why.
Switch to $table->integer('position')->nullable(); or set a position in each array element.

wtf stop commenting this is from 2013

hahhahaha @robclancy

Was this page helpful?
0 / 5 - 0 ratings