Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nohortax's avatar

Insert value list does not match column : I have the exact amount of columns

Hello guys,

I'm trying to insert data into a table by using a seeder file. I have the same number of columns indicated for each group of data, but I still get the error "SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 41"

class ResultatSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('resultats')->insert([
            // Amay CGM61003
            [
                'annee' => 2018,
                'resultat' => 12.00,
                'nb_bureaux' => 5,
                'bureaux_depouilles' => 5,
                'validation' => 1,
                'maj' => '2018-10-15 10:58:47',
                'previous_data' => 5,
                'election_liste_zone_id' => 1
            ],
            
            [
                'annee' => 2018,
                'resultat' => 54.43,
                'nb_bureaux' => 5,
                'bureaux_depouilles' => 5,
                'validation' => 1,
                'maj' => '2018-10-15 10:58:47',
                'previous_data' => 5,
                'election_liste_zone_id' => 3
            ],
            
            [
                'annee' => 2018,
                'resultat' => 33.11,
                'nb_bureaux' => 5,
                'bureaux_depouilles' => 5,
                'validation' => 1,
                'maj' => '2018-10-15 10:58:47',
                'previous_data' => 5,
                'election_liste_zone_id' => 4
            ],
            // -------------------------------------
            // Ans
            [
                'annee' => 2018,
                'resultat' => 7.94,
                'nb_bureaux' => 10,
                'bureaux_depouilles' => 10,
                'validation' => 1,
                'maj' => '2018-10-15 10:58:50',
                'previous_data' => 10,
                'election_liste_zone_id' => 8
            ],

            [
                'annee' => 2018,
                'resultat' => 9.85,
                'nb_bureaux' => 10,
                'bureaux_depouilles' => 10,
                'validation' => 1,
                'maj' => '2018-10-15 10:58:50',
                'previous_data' => 10,
                'election_liste_zone_id' => 10
            ],
...

the error message :

Illuminate\Database\QueryException 

  SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 41

The columns of my table

| Field                  | Type             | Null | Key | Default             | Extra                         |
+------------------------+------------------+------+-----+---------------------+-------------------------------+
| id                     | int(10) unsigned | NO   | PRI | NULL                | auto_increment                |
| annee                  | year(4)          | NO   |     | NULL                |                               |
| resultat               | float            | NO   |     | NULL                |                               |
| nb_bureaux             | int(11)          | YES  |     | NULL                |                               |
| bureaux_depouilles     | int(11)          | YES  |     | NULL                |                               |
| validation             | tinyint(4)       | NO   |     | NULL                |                               |
| maj                    | datetime         | YES  |     | NULL                |                               |
| previous_data          | int(11)          | YES  |     | NULL                |                               |
| election_liste_zone_id | int(10) unsigned | NO   | MUL | NULL                |                               |
| created_at             | timestamp        | NO   |     | current_timestamp() |                               |
| updated_at             | timestamp        | NO   |     | current_timestamp() | on update current_timestamp() |
| slug                   | varchar(100)     | YES  |     | NULL                |      

Does anyone have an idea why I get that error message even if I'm entering the same amount of data for each ?

0 likes
4 replies
Nohortax's avatar

UPDATE :

I started to seed the first ones (by 5 or 6) by commenting the rest, then commenting what I seeded and uncommenting the next ones, and it worked. At some point, I got the error again, and I seeded one instead of 5 or 6, it worked. Then the next one gave me another error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into `resultats` (`annee`, `resultat`, `0`, `bureaux_depouilles`, `election_liste_zone_id`, `maj`, `nb_bureaux`, `previous_data`, `validation`) values (2018, 24, 50, 3, 197, 2018-10-15 10:58:54, 3, 3, 0))
// [
            //     'annee' => 2018,
            //     'resultat' => 10.88,
            //     'nb_bureaux' => 3,
            //     'bureaux_depouilles' => 3,
            //     'validation' => 0,
            //     'maj' => '2018-10-15 10:58:54',
            //     'previous_data' => 3,
            //     'election_liste_zone_id' => 196
            // ]
            
            [
                'annee' => 2018,
                'resultat' => 24,50,
                'nb_bureaux' => 3,
                'bureaux_depouilles' => 3,
                'validation' => 0,
                'maj' => '2018-10-15 10:58:54',
                'previous_data' => 3,
                'election_liste_zone_id' => 197
            ]

No column is called 0 !

JussiMannisto's avatar
Level 50

@Nohortax You're trying to insert this:

'resultat' => 24,50,

Which is equivalent to this:

'resultat' => 24,
0 => 50,

Use period as the decimal separator.

3 likes
Nohortax's avatar

@JussiMannisto Thank you ! I read and re-read the lines many times and I couldn't see that there was a comma instead of a dot ! I guess when you see the same lines for too long you don't notice such small details anymore

Please or to participate in this conversation.