Search code examples
djangodjango-userena

Added an Image Field, getting OperationalError: Column does not exist


I am using Userena, and in my profile class, I added an ImageField, now I get OperationalError, Column does not exist everytime I reach the sign up page on my site.

Here is the code below.

from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from userena.models import UserenaBaseProfile

class MyProfile(UserenaBaseProfile):
    user = models.OneToOneField(User,
                                unique=True,
                                verbose_name=_('user'),
                                related_name='my_profile')
    favourite_snack = models.CharField(_('favourite snack'),
                                       max_length=5
    coverpic = models.ImageField(upload_to="site_media/media/covers/", null=True, blank=True)

I have already ran syncdb and a South Migration dozens of times after adding the ImageField, so I'm not sure if that is the problem.

What am I doing wrong here?


Solution

  • South can get messed up sometimes. The database field does not exist on your database, but south thinks it does.

    The solution I use when this happens is to fake a delete migration and then add the field after south thinks the field has been deleted.

    1. Comment out the coverpic line and then run ./manage.py
    2. schemamigration app --auto Run a fake migration to make south think that it's removing the field | ./manage.py migrate app --fake
    3. Uncomment the coverpic line and then run ./manage.py schemamigration app --auto
    4. Add the field ./manage.py migrate app