laravel Column not found: 1054 Unknown column 'created_at' in 'order clause'
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel Eloquent Mystery Solved: Why 'created_at' Still Fails When You Set $timestamps = false
As a senior developer working with Laravel and Eloquent, we often run into situations where the framework seems to contradict our explicit instructions. One common and frustrating scenario involves timestamps: setting $timestamps = false on a model, yet still encountering database errors like SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_at' in 'order clause'.
This post will dissect why this happens, explore the root cause related to Eloquent conventions, and provide robust solutions so you can manage your database schema and model definitions with confidence.
The Conflict: Eloquent Conventions vs. Database Reality
The error you are seeing—Unknown column 'created_at' in 'order clause'—tells us that Laravel (specifically the underlying query generated by Eloquent) is attempting to sort or select a column named created_at from your videos_comments table, but the database reports that this column does not exist.
This conflict arises from the difference between what Eloquent expects and what the physical database is.
When you define a model with $timestamps = false;, you are telling Eloquent not to automatically manage or save the created_at and updated_at fields during standard CRUD operations. However, Eloquent's conventions (especially when dealing with relationships like latest() or default sorting) often still rely on these timestamps existing in the underlying table structure for convenience.
In your case, even though you disabled them in the model, the query generated by methods like ->latest() might still implicitly assume these columns exist, leading to the failure when the database schema doesn't match that assumption.
Diagnosing the Issue: Schema Mismatch
The most likely cause is a mismatch between your Eloquent model definition and the actual structure of your database table (videos_comments).
Your provided code snippets indicate you are trying to control timestamps, but the resulting SQL query is breaking because the column simply isn't there in the physical schema:
// In VideoComment.php
protected $table = 'videos_comments';
public $timestamps = false; // Telling Eloquent not to manage these fields
If you set $timestamps = false, you must ensure that the corresponding columns (created_at and updated_at) are not present in your table schema, or if they are present, ensure that no part of your query attempts to use them. If the database already has these columns because they were added via a default Laravel migration, but you explicitly disable timestamps in Eloquent, this conflict occurs.
Practical Solutions for Timestamp Management
There are three primary ways to resolve this issue, depending on your application's requirements:
Solution 1: Aligning Database Schema (Recommended)
The cleanest approach is to ensure your database schema perfectly reflects what your model expects. If you genuinely do not need audit timestamps for a specific table (videos_comments), remove the timestamp columns from the migration file that created or modified that table.
If you are using Laravel, remember that proper database structure is key, and frameworks like those promoted by laravelcompany.com rely heavily on clean migrations to maintain data integrity across the stack.
Solution 2: Explicitly Handling Ordering (The Eloquent Fix)
If you must keep the columns in the table but want to ignore them for sorting, you need to explicitly tell Eloquent which fields to order by, bypassing any implicit timestamp usage. This is often done by using raw expressions or ensuring your ordering logic only uses existing, non-timestamp columns.
For example, if you were trying to order by a custom date field instead of the default timestamps:
// Example fix in your controller/query:
$video->comments()->orderBy('date', 'desc')->get(); // Use your custom column instead of relying on defaults
Solution 3: Customizing Model Behavior (Advanced)
For more complex scenarios, you can customize Eloquent's behavior by overriding the getTimestamps method or using model events, though this is generally overkill if simply removing the columns (Solution 1) solves the problem. For simple timestamp disabling, sticking to clean migrations is the most maintainable path.
Conclusion
The error "Unknown column 'created_at'" when $timestamps = false is set highlights a critical point in database-driven development: the application layer must perfectly align with the data layer. Do not let Eloquent's powerful conventions override fundamental schema integrity. Always verify your migrations against your model definitions. By ensuring that your database structure matches your Eloquent expectations, you eliminate these frustrating runtime errors and build more robust applications.