Error Encyclopedia

Column Does Not Exist Error

Fix 'column does not exist' SQL errors in PostgreSQL, MySQL, and other databases when querying or migrating schemas.

What Does This Error Mean?

The 'column does not exist' error means the SQL query references a column that is not present in the table schema. This can happen due to missing migrations, incorrect column names, or quoting issues.

Common Causes

1

Column was added in a migration that hasn't been run yet

2

Typo in the column name

3

Mixed case column names without proper quoting

4

Querying the wrong table or schema

5

Using an alias that shadows the actual column name

6

ORM model not synced with database schema

How to Fix It

Check table schema

Verify the columns in your table match your query.

-- PostgreSQL: describe table
\d table_name

-- Or query information_schema
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'users'
ORDER BY ordinal_position;

-- MySQL
DESCRIBE users;

Handle column case sensitivity

Unquoted identifiers in PostgreSQL are case-folded to lowercase.

-- ❌ Mixed case column
SELECT "UserId" FROM users;  -- Only works if column is literally "UserId"

-- ✅ Use lowercase (PostgreSQL folds unquoted names)
SELECT userid FROM users;

-- OR quote exactly
SELECT "UserId" FROM users;  -- Column must be defined as "UserId"

Run pending migrations

Ensure all database migrations have been applied.

# Prisma
npx prisma migrate deploy

# TypeORM
npx typeorm migration:run

# Sequelize
npx sequelize-cli db:migrate

# Knex
npx knex migrate:latest

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category: