Search code examples
sqldjangodjango-modelsdjango-admindjango-registration

Django, UserProfile inheritance nightmare?


I'm using both django-userena and django-facebook as my main registration apps.

Let's inherit my own UserProlfile from both of them:

from userena.models import UserenaBaseProfile
from django_facebook.models import FacebookProfileModel


class UserProfile(UserenaBaseProfile , FacebookProfileModel):
    user = models.OneToOneField(User, unique=True, verbose_name=_('user'), related_name='user_profile')
    department     = models.ForeignKey('Department' , null = True , blank = True , related_name=_('user'))
    name           = models.CharField(max_length = 100)
    birthday       = models.DateField()

    def __unicode__(self):
        return self.name

class Student(UserProfile):
    courses = models.ManyToManyField(Course , null = True, blank = True, related_name = _('student'))

Now, whenever I want go see the Student within the Django Admin, I get this error :

Exception Value: No such column: profiles_userprofile.about_me

But, it EXISTS !! this is the output of ./manage.py sqlall profiles :

BEGIN;
CREATE TABLE "profiles_userprofile" (
    "id" integer NOT NULL PRIMARY KEY,
    "mugshot" varchar(100) NOT NULL,
    "privacy" varchar(15) NOT NULL,

    "about_me" text, ## Her it is !!!

    "facebook_id" bigint UNIQUE,
    "access_token" text NOT NULL,
    "facebook_name" varchar(255) NOT NULL,
    "facebook_profile_url" text NOT NULL,
    "website_url" text NOT NULL,
    "blog_url" text NOT NULL,
    "image" varchar(255),
    "date_of_birth" date,
    "gender" varchar(1),
    "raw_data" text NOT NULL,
    "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id"),
    "department_id" integer,
    "name" varchar(100) NOT NULL,
    "birthday" date NOT NULL
)
;

I'm so so confused .. can anybody gives me a hint please ??


Solution

  • sqlall only tells you the SQL that would be sent, if you were running syncdb for the first time. It does not give you the actual state of the database. You must actually run syncdb to have the tables created. Further, if any of the tables already existed, syncdb will not make any changes to the table(s); it only creates tables, never alters them.

    If you need to alter the table, you will either have to manually run SQL on your database, or use something like South to do a migration.