Laravel Unknown Column 'updated_at'
The error Unknown column 'updated_at' appears when you attempt to insert a record into a table that does not physically contain that column, even if your code never explicitly references $model->updated_at. This usually happens because you are relying on Laravel's automatic timestamp management without configuring the model or migration correctly.
In your specific scenario, you are creating a User model that maps to a database table named gebruikers. You have defined two custom fields: naam (name) and wachtwoord (password). However, the error message indicates that Laravel is trying to insert data into an updated_at column during your save operation. Since you confirmed you are not using the updated_at field in your code, the issue lies entirely in how the database schema or the model configuration interacts with Laravel's default behavior.
The Default Timestamp Behavior
Laravel models have a built-in feature called "Automatic Timestamps." By default, if a model class does not define any specific date attributes (like $fillable containing created_at or updated_at, or defining accessor/mutator methods), and the database table lacks these columns, Laravel will automatically attempt to fill them upon saving.
The core issue is that your gebruikers table was likely created without the updated_at column, but your application expects it because of a missing configuration flag in the model. When you call $user->save(), Laravel checks the model's configuration. If the table doesn't have the expected columns and the model hasn't told Laravel to skip them, an exception is thrown.
To resolve this, you must explicitly tell Laravel that your table does not require automatic timestamps. This is done by adding a protected property to your User model class:
protected $dates = [];
// OR more specifically for your case:
public $timestamps = false;
Adding public $timestamps = false; to your User model instructs the Eloquent ORM to stop trying to fill created_at and updated_at columns automatically. This aligns the behavior with your database schema, which only contains naam and wachtwoord.
Checking Your Migration or Schema Definition
If you are using migrations to define your gebruikers table, ensure that the column definitions match your intent. If you previously ran a migration based on a Laravel tutorial that included timestamps, but now want to remove them, you have two options:
Modify the Model (Recommended for existing DB):
As mentioned above, adding$timestamps = falseto the model is the quickest fix if you cannot alter the database schema immediately. This prevents Laravel from trying to write to a non-existent column.Alter the Migration:
If you are defining the table in a migration file, ensure thatcreated_atandupdated_atare not included in the schema creation:Schema::create('gebruikers', function (Blueprint $table) { $table->string('naam')->unique(); $table->string('wachtwoord'); // Do NOT include created_at or updated_at here });
The fillable Property Nuance
There is a secondary consideration regarding the $fillable property. In older versions of Laravel (and in your provided code snippet), models did not strictly enforce fillable attributes unless defined, making them effectively "mass assignable" by default. However, modern best practices encourage defining $fillable.
If you decide to add $fillable = ['naam', 'wachtwoord']; to your model, you must also set timestamps = false. If you keep timestamps enabled but restrict fillable attributes, Laravel will still try to insert the timestamp columns unless they are explicitly in the fillable array. Since your table lacks these columns, keeping them out of the fillable list while disabling automatic timestamps is the safest approach to avoid SQL errors.
Summary of the Fix
The root cause is a mismatch between the database schema and Laravel's default model configuration. The database gebruikers table does not have updated_at, but the User model assumes it exists. By adding public $timestamps = false; to your User model, you explicitly disable this automatic behavior. This ensures that $user->save() only attempts to insert the columns you actually define: naam and wachtwoord.
