Database Laravel 8 Laravel 9 Laravel 10 Laravel 11 Laravel 12

Unknown Column Error in Laravel - How to Fix

This error occurs when querying or inserting data with a column name that doesn't exist in the database table.

The Error

Error Message
SQLSTATE[42S22]: Column not found: 1054 Unknown column

Common Causes

  1. 1 Column doesn't exist in table
  2. 2 Typo in column name
  3. 3 Migration not run after adding column
  4. 4 Model $fillable referencing non-existent column
  5. 5 Using wrong table alias in query

Solutions

1

Run pending migrations

Bash
php artisan migrate
2

Check which columns exist

Bash
php artisan tinker
>>> Schema::getColumnListing('posts')
3

Create migration to add missing column

Bash
php artisan make:migration add_status_to_posts_table --table=posts

// In migration up() method
$table->string('status')->default('draft');
4

Check for typos in your query

PHP
// Wrong
Post::where('staus', 'published')->get();

// Correct
Post::where('status', 'published')->get();

Need Help With Your Laravel Project?

I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.

Hafiz Riaz

About Hafiz

Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.

Get in touch →

Related Errors