Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!