jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting
https://django-polymorphic.readthedocs.io
Other
1.65k stars 280 forks source link

getting an error #174

Closed kodeine closed 8 years ago

kodeine commented 8 years ago

i am kinda new to python/django. I get the following error, django.db.utils.OperationalError: (1054, "Unknown column 'models_request.polymorphic_ctype_id' in 'field list'")


class Request(PolymorphicModel):
    TYPES = (
        ('twitter', 'Twitter'),
        ('facebook', 'Facebook'),
        ('text', 'Text'),
    )
    STATUSES = (
        ('active', 'Active'),
        ('pending', 'Pending'),
        ('cancelled', 'Cancelled'),
    )
    phone = models.CharField(max_length=15)
    type = models.CharField(max_length=15, choices=TYPES)
    status = models.CharField(max_length=15, choices=STATUSES, default='active')
    updated_at = models.DateTimeField(auto_now=True)
    created_at = models.DateTimeField(auto_now_add=True)

    # communication = models.ManyToManyField(Communication, related_name='communication')

    #objects = RequestQuerySet.as_manager()

    class Meta:
        unique_together = ('phone', 'type',)

    def __unicode__(self):
            return u"%s %s" % (self.phone, self.type)

class Communication(Request):
    text = models.TextField()
    expect = models.CharField(max_length=75, default='')

    def __unicode__(self):
            return u"%s : %s" % (self.text, self.expect)
vdboor commented 8 years ago

I think you added the polymorphic model later, and didn't migrate your database. Consider recreating your tables if you've just started a fresh project