If you’ve been working with Django for a while, you might have encountered the frustrating error: ProgrammingError: column does not exist. I’ve faced this issue multiple times, especially when working on data-driven applications for clients.
This error typically occurs when your Django app tries to access a database column that isn’t present, usually due to schema mismatches or migration issues. In this article, I’ll share practical methods to troubleshoot and fix this error efficiently.
Let’s get in!
What Causes the “Column Does Not Exist” Error in Django?
This error usually happens when the database schema is out of sync with your Django models. Common scenarios include:
- You added or renamed a model field but didn’t run migrations.
- You manually edited the database outside Django’s ORM.
- Your migrations failed or were only partially applied.
- You’re referencing a column that never existed in the database.
Understanding the root cause helps you apply the right fix quickly.
Method 1: Verify Your Model and Database Schema
The first step is to double-check your Django model and ensure the field exists as expected.
For example, suppose you have a simple Employee model:
from django.db import models
class Employee(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(unique=True)
salary = models.DecimalField(max_digits=10, decimal_places=2)If you recently added the salary field but forgot to migrate, Django will try to query a salary column that doesn’t exist in your database, causing the error.
You can see the output in the screenshot below.


Method 2: Run Migrations to Sync Database Schema
One of the most common reasons for this error is missing migrations. Always make sure to:
- Create migrations after model changes:
python manage.py makemigrations- Apply migrations to update the database schema:
python manage.py migrateIf you’re working on a project with multiple environments (development, staging, production), ensure migrations are applied to all.
Check out ModuleNotFoundError: No module named Django
Method 3: Inspect Your Database Directly
Sometimes, despite running migrations, the database might not reflect the expected schema. This can happen if migrations are interrupted or manually altered.
If you’re using PostgreSQL (common in US enterprise apps), connect to your database and check the table columns:
psql your_database_nameThen run:
\d your_appname_employee;This command lists all columns in the employee table. Confirm whether the column (e.g., salary) exists.
If it doesn’t, you might need to:
- Reapply migrations.
- Manually add the column (not recommended unless you know what you’re doing).
- Reset migrations (see Method 5).
Method 4: Check Your Query and ORM Usage
Sometimes the error is triggered by a typo or incorrect field reference in your queryset.
For example, this will cause the error if salary doesn’t exist:
Employee.objects.filter(salary__gt=50000)Double-check field names in your code and ensure they match your model fields exactly.
Read How to View Uploaded Files in Django
Method 5: Reset Migrations (Use with Caution)
If your migration history is corrupted or out of sync, resetting migrations can help — especially in development.
Warning: This will delete migration history and potentially your database schema. Always back up your data.
Steps:
- Delete all migration files in your app’s
migrations/folder except__init__.py. - Drop the database tables or the entire database.
- Recreate the database.
- Run:
python manage.py makemigrations
python manage.py migrateThis will create a fresh schema matching your current models.
Check out Python Django: Get Admin Password
Full Example: Fix the Error in a Sample Django Project
Here’s a complete example demonstrating the fix workflow.
models.py
from django.db import models
class Employee(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(unique=True)
salary = models.DecimalField(max_digits=10, decimal_places=2) # Newly added fieldSteps:
- After adding
salary, run:
python manage.py makemigrationsYou should see output like:
Migrations for 'your_app':
your_app/migrations/0002_employee_salary.py
- Add field salary to employee- Apply migrations:
python manage.py migrate- Verify in Django shell:
python manage.py shellfrom your_app.models import Employee
Employee.objects.filter(salary__gt=50000)No more “column does not exist” error should appear.
Read Upload Image File in Django
Additional Tips from My Experience
- Always version-control your migration files. This helps track changes and avoid conflicts.
- Use Django’s
showmigrationscommand to see applied migrations. - If working in teams, communicate migration changes.
- For production databases, consider using a staging environment to test migrations before applying.
Encountering ProgrammingError: column does not exist can feel daunting, but with these practical steps, you can quickly identify and resolve the root cause. Keeping your models and database schema in sync is key to smooth Django development.
If you follow these methods, you’ll spend less time troubleshooting and more time building great applications.
You may also read:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.