Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms More on Models Abstract Inheritance

Pachal Debbarma
PLUS
Pachal Debbarma
Courses Plus Student 3,597 Points

Abstract inheritance issues with migrating the models.

models.py

class Step(models.Model):
    title = models.CharField(max_length = 255)
    description = models.TextField()
    order = models.IntegerField(default = 0)
    course = models.ForeignKey(Course)
    class meta:
        abstract = True
        ordering = ['order',]
    def __str__(self):
        return self.title

class Text(Step):
    content= models.TextField(blank=True,default ='')

admin.py

from django.contrib import admin
from .models import Course,Step
# Register your models here.
class StepInline(admin.StackedInline):
    model = Step
class CourseAdmin(admin.ModelAdmin):
   # inlines = [StepInline,]   
   pass 
admin.site.register(Course,CourseAdmin)
#admin.site.register(Step)

Even after following the instructions when i migrate the models i get the following error in terminal (django.core.exceptions.FieldError: Local field 'content' in class 'Text' clashes with field of the same name from base c)

Can anybody suggest me what that even mean?Please i need help

Haydar Al-Rikabi
Haydar Al-Rikabi
5,971 Points

The only scenario I can think of is that your copied the "content" field from "Step" to "Text", saved models.py, then removed the "content" field from "Step" and run the migrate command without saving models.py again. So, you have now two content fields which caused this error. Make sure to save your models.py before doing any migrations!