Skip to main content

Python Django: How to Resolve "django.core.exceptions.FieldDoesNotExist" in Python

When working with Django models, you may encounter the error django.core.exceptions.FieldDoesNotExist. This exception means Django can't find a field you're trying to access on a model, usually because of a typo, a missing field definition, or an incomplete migration.

In this guide, we'll cover all the common causes of this error and walk through practical solutions with examples to help you fix it quickly.

What Is FieldDoesNotExist?

FieldDoesNotExist is a Django exception raised when you reference a field name that doesn't exist on a model. This can happen in views, serializers, admin configurations, querysets, or anywhere you interact with model fields by name.

The error typically looks like:

django.core.exceptions.FieldDoesNotExist: ModelName has no field named 'field_name'

Common Causes

Before jumping into solutions, let's identify the most frequent reasons this error occurs:

CauseDescription
Typo in field nameMisspelling a field name when querying or accessing it
Missing field definitionReferencing a field that was never added to the model
Unmigrated changesAdding a field to the model code but not running migrations
Wrong modelAccessing a field on a model where it doesn't exist
Inheritance issuesExpecting a field from a parent model that isn't defined there
Stale admin/serializer configAdmin classes or serializers referencing fields that were renamed or removed

Solutions

Solution 1: Fix Misspelled Field Names

The most common cause is a simple typo. Python is case-sensitive, so Price, price, and PRICE are all different names.

❌ Wrong: Typo in the field name:

from django.db import models

class Product(models.Model):
name = models.CharField(max_length=100)
price = models.IntegerField()

# Querying with a misspelled field name
results = Product.objects.filter(prce=1000) # 'prce' instead of 'price'

Output:

django.core.exceptions.FieldDoesNotExist: Product has no field named 'prce'

✅ Correct: Use the exact field name from the model:

results = Product.objects.filter(price=1000)
Quick Debugging

If you're unsure what fields exist on a model, inspect them programmatically:

# List all field names on a model
field_names = [f.name for f in Product._meta.get_fields()]
print(field_names)
# Output: ['id', 'name', 'price']

This is especially helpful when working with models you didn't write yourself.

Solution 2: Add the Missing Field and Migrate

If you're trying to access a field that was never defined in the model, you need to add it and run migrations.

❌ Wrong: Accessing a field that doesn't exist on the model:

class Product(models.Model):
name = models.CharField(max_length=100)
price = models.IntegerField()

# 'category' was never defined
products = Product.objects.filter(category="Electronics")

Output:

django.core.exceptions.FieldDoesNotExist: Product has no field named 'category'

✅ Correct: Add the field to the model and migrate:

Step 1: Add the field to your model:

class Product(models.Model):
name = models.CharField(max_length=100)
price = models.IntegerField()
category = models.CharField(max_length=50, default="General") # New field

Step 2: Create and apply the migration:

python manage.py makemigrations
python manage.py migrate

Step 3: Now the query works:

products = Product.objects.filter(category="Electronics")
caution

When adding a new field to an existing model with data, you must provide a default value or allow null=True. Otherwise, Django won't know what value to assign to existing rows:

# Option 1: Provide a default
category = models.CharField(max_length=50, default="General")

# Option 2: Allow null
category = models.CharField(max_length=50, null=True, blank=True)

Solution 3: Ensure Migrations Are Up to Date

If you've added a field to your model code but the error persists, your migrations may not have been applied properly.

Check for pending migrations:

python manage.py showmigrations

Look for unapplied migrations (marked with [ ] instead of [X]):

app_name
[X] 0001_initial
[ ] 0002_product_category ← Not applied!

Apply pending migrations:

python manage.py migrate

If migrations are corrupted or out of sync, you may need to recreate them:

# 1. Delete migration files (keep __init__.py)
# 2. Recreate migrations
python manage.py makemigrations app_name

# 3. If the database is out of sync, fake the migration
python manage.py migrate --fake app_name zero
python manage.py migrate app_name
caution

Only use --fake and migration deletion in development environments. In production, always resolve migration issues carefully to avoid data loss.

Solution 4: Check You're Using the Correct Model

When a project has multiple models, it's easy to query a field on the wrong model:

❌ Wrong: Querying category on Order instead of Product:

class Product(models.Model):
name = models.CharField(max_length=100)
category = models.CharField(max_length=50)

class Order(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField()

# 'category' exists on Product, not on Order
orders = Order.objects.filter(category="Electronics") # FieldDoesNotExist!

✅ Correct: Use the relationship to traverse to the right model:

# Use double underscores to follow the foreign key
orders = Order.objects.filter(product__category="Electronics")

Solution 5: Fix Admin and Serializer Configurations

The error frequently appears in Django Admin or DRF serializers when they reference fields that have been renamed or removed from the model.

❌ Wrong: Admin class references a removed field:

from django.contrib import admin
from .models import Product

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ['name', 'price', 'description'] # 'description' doesn't exist

Output:

django.core.exceptions.FieldDoesNotExist: Product has no field named 'description'

✅ Correct: Only reference fields that exist on the model:

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
list_display = ['name', 'price', 'category'] # All fields exist

The same applies to Django REST Framework serializers:

# ❌ Wrong
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ['name', 'price', 'description'] # 'description' doesn't exist

# ✅ Correct
class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = ['name', 'price', 'category']

Solution 6: Handle Model Inheritance Properly

If you're using model inheritance, make sure the field you're accessing is defined in the correct class in the hierarchy:

❌ Wrong: Accessing a child field on the parent model:

class Vehicle(models.Model):
make = models.CharField(max_length=50)
model = models.CharField(max_length=50)

class Car(Vehicle):
num_doors = models.IntegerField()

# 'num_doors' exists on Car, not Vehicle
vehicles = Vehicle.objects.filter(num_doors=4) # FieldDoesNotExist!

✅ Correct: Query the correct model:

cars = Car.objects.filter(num_doors=4)

Debugging Workflow

When you encounter FieldDoesNotExist, follow this systematic approach:

# Step 1: Identify which field is missing from the error message
# "Product has no field named 'descripion'"

# Step 2: Check the model's actual fields
from myapp.models import Product
print([f.name for f in Product._meta.get_fields()])
# Output: ['id', 'name', 'price', 'category']

# Step 3: Compare with what you're referencing
# 'descripion' → likely a typo for 'description'
# But 'description' isn't in the field list either
# → Need to either add the field or use an existing one

# Step 4: Check migration status
# Run: python manage.py showmigrations

Quick Reference

CauseFix
Typo in field nameCorrect the spelling; check with _meta.get_fields()
Field never definedAdd it to the model and run migrations
Migrations not appliedRun python manage.py migrate
Wrong modelUse the correct model or follow relationships with __
Admin/serializer references old fieldUpdate list_display, fields, etc. to match current model
Inheritance confusionQuery the model where the field is actually defined

Conclusion

The django.core.exceptions.FieldDoesNotExist error occurs when you reference a field name that doesn't exist on a Django model.

The fix depends on the root cause: correct typos in field names, add missing fields and run migrations, verify you're querying the right model, and update admin or serializer configurations to match your current model schema.

When in doubt, use Model._meta.get_fields() to inspect the actual fields available on any model, and always run python manage.py showmigrations to confirm your database schema is up to date.