Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #2198

Closed
iflow opened this issue Aug 29, 2013 · 13 comments

Comments

@iflow
Copy link

iflow commented Aug 29, 2013

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

@robclancy
Copy link
Contributor

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.

@JoostK
Copy link
Contributor

JoostK commented Aug 29, 2013

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)

@robclancy
Copy link
Contributor

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.

@WMeldon
Copy link
Contributor

WMeldon commented Aug 29, 2013

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.

@iflow
Copy link
Author

iflow commented Aug 30, 2013

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.

@WMeldon
Copy link
Contributor

WMeldon commented Aug 30, 2013

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

@iflow
Copy link
Author

iflow commented Sep 2, 2013

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,
        ),

@WMeldon
Copy link
Contributor

WMeldon commented Sep 3, 2013

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

@taylorotwell
Copy link
Member

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

@aryanagrahari
Copy link

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)

@tomjamon
Copy link

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.

@robclancy
Copy link
Contributor

wtf stop commenting this is from 2013

@TowlieeNetworks

This comment has been minimized.

@laravel laravel locked and limited conversation to collaborators Feb 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants