sqldiff reports incorrect differences between database and model... I think

63 views
Skip to first unread message

Thomas Wessel

unread,
May 17, 2011, 4:43:06 AM5/17/11
to django-extensions
I have Django CMS 2.1.3 installed. It has among many models:

from django.contrib.auth.models import User, Group
# (...)
class PageUser(User):
"""Cms specific user data, required for permission system
"""
created_by = models.ForeignKey(User,
related_name="created_users")

class Meta:
verbose_name = _('User (page)')
verbose_name_plural = _('Users (page)')
app_label = 'cms'

#__unicode__ = lambda self: unicode(self.user)


And this is how the beginning of the parent model looks (Django 1.2.5,
django/contrib/auth/models.py):
class User(models.Model):
"""
Users within the Django authentication system are represented by
this model.

Username and password are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30,
unique=True, help_text=_("Required. 30 characters or fewer. Letters,
numbers and @/./+/-/_ characters"))
first_name = models.CharField(_('first name'), max_length=30,
blank=True)
last_name = models.CharField(_('last name'), max_length=30,
blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
password = models.CharField(_('password'), max_length=128,
help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=
\"password/\">change password form</a>."))
is_staff = models.BooleanField(_('staff status'), default=False,
help_text=_("Designates whether the user can log into this admin
site."))
is_active = models.BooleanField(_('active'), default=True,
help_text=_("Designates whether this user should be treated as active.
Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'),
default=False, help_text=_("Designates that this user has all
permissions without explicitly assigning them."))
last_login = models.DateTimeField(_('last login'),
default=datetime.datetime.now)
date_joined = models.DateTimeField(_('date joined'),
default=datetime.datetime.now)
groups = models.ManyToManyField(Group, verbose_name=_('groups'),
blank=True,
help_text=_("In addition to the permissions manually
assigned, this user will also get all permissions granted to each
group he/she is in."))
user_permissions = models.ManyToManyField(Permission,
verbose_name=_('user permissions'), blank=True)
objects = UserManager()

class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
#(...)

So how does Django handle model inheritance? To my understanding, if
nothing is stated in the Meta class, it will use multitable
inheritance (http://docs.djangoproject.com/en/dev/topics/db/models/
#multi-table-inheritance).

So in this particular case, the cms_userpage table should NOT contain
any information defined in the class User. Right?

However when I run "manage.py sqldiff cms" I get:
-- Model: PageUser
ALTER TABLE "cms_pageuser"
ADD "username" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "first_name" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "last_name" varchar(30);
ALTER TABLE "cms_pageuser"
ADD "is_active" boolean;
ALTER TABLE "cms_pageuser"
ADD "email" varchar(75);
ALTER TABLE "cms_pageuser"
ADD "is_superuser" boolean;
ALTER TABLE "cms_pageuser"
ADD "is_staff" boolean;
ALTER TABLE "cms_pageuser"
ADD "last_login" timestamp with time zone;
ALTER TABLE "cms_pageuser"
ADD "password" varchar(128);
ALTER TABLE "cms_pageuser"
ADD "id" serial;
ALTER TABLE "cms_pageuser"
ADD "date_joined" timestamp with time zone;
ALTER TABLE "cms_pageuser"
ADD UNIQUE ("id");
ALTER TABLE "cms_pageuser"
ADD UNIQUE ("username");


It looks like sqldiff thinks that the table of the child model should
inherit all information from the parent model.

Have I misunderstood something? Or how can this be explained?

I am using Django Extensions 0.4.1.

Sincerely, Thomas Wessel

Thomas Larsen Wessel

unread,
May 24, 2011, 12:39:51 PM5/24/11
to django-extensions
Hi again

I allow myself to repeat my question, since I have had no responses. Please tell me if the question is unclear, of if I am writing the wrong persons.

In essence: I was happy to find the sqldiff functionality in the django extensions. But it tells me of a lot of differences between model and database, where I believe that the models and database _does_ match each other.

If I am right, then the sqldiff tool is suddenly misleading/incorrect, and this should be added to your documentation.

If I am wrong, then I hope someone can tell me what I have misunderstood.

Sincerely, Thomas Wessel

trbs

unread,
Jun 2, 2011, 1:30:59 PM6/2/11
to django-extensions
Sorry for the late reply.
I'm very busy and have little time to watch the mailinglist, answer
questions and work on django-extensions. :(

Yes your in the right spot here, it's just a very very low traffic
mailinglist.

Please try the latests version (or the bleeding edge code on github)
this might help.. there have been some work
on sqldiff between 0.4 and current I think (but not much).
Reply all
Reply to author
Forward
0 new messages