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

oyazigi's avatar

SQLSTATE[42S22]: Column not found: 1054

thats my UserFactory

and the migration file

and the seeder

and this is the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (Connection: mysql, SQL: insert into `usuario` (`login`, `pass`, `cargo`, `updated_at`, `created_at`) values (Judge Boyle I, $2y$12$wjh5yl2Rw9VVc9TokGlH5uFXulI2JJzJM4UJXbPDmjdp6yY.aVzR6, 1, 2025-03-05 02:29:37, 2025-03-05 02:29:37))  

the problem is: i used to have those fields updated_at and created_at on my 'usuario' table, but i took them out of the code, but for some reason my seeder still expects that these two tables are still on the database

0 likes
2 replies
Tray2's avatar
Tray2
Best Answer
Level 73

You need to add the timestamps to this migration.

  Schema::create('usuario', function (Blueprint $table) {
            $table->id('usuarioid');
            $table->string('login')->unique();
            $table->string('pass');
            $table->foreignId('cargo');
        });

It should be

  Schema::create('usuario', function (Blueprint $table) {
            $table->id('usuarioid');
            $table->string('login')->unique();
            $table->string('pass');
            $table->foreignId('cargo');
			$table->timestamps();
        }); 

However there are a lot of problems with your database model.

It does not follow the conventions of Laravel.

  1. id/primary key columns should be named id
  2. foreign key columns should be named <model they are referencing>_id, like user_id
  3. use english to name tables and fields
  4. Table names should be in plural form

Then of course, don't roll your own authentication, use a starter kit for that.

Oh and give these a read or three.

https://tray2.se/posts/database-design

https://tray2.se/posts/database-design-part-2

https://tray2.se/posts/sqlerrm

https://tray2.se/posts/properly-formed-foreign-keys-are-your-best-friends

3 likes

Please or to participate in this conversation.