Opened 11 years ago
Closed 11 years ago
#21786 closed Bug (fixed)
migrate fails with certain mixin/model combinations
Reported by: | Gabe Jackson | Owned by: | Andrew Godwin |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | migrations |
Cc: | Tim Graham | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
manage migrate fails with:
Operations to perform: Synchronize unmigrated apps: admin, contenttypes, langapp, auth, sessions Apply all migrations: (none) Synchronizing apps without migrations: Creating tables... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session Creating table langapp_mymodela_translation Creating table langapp_mymodela Creating table langapp_mymodelb_translation Creating table langapp_mymodelb Creating table langapp_mymodelc Creating table langapp_mymodeld Installing custom SQL... Installing indexes... Installed 0 object(s) from 0 fixture(s) Running migrations: No migrations needed. Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/core/management/base.py", line 244, in run_from_argv self.execute(*args, **options.__dict__) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/core/management/base.py", line 291, in execute output = self.handle(*args, **options) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 140, in handle changes = autodetector.changes(graph=executor.loader.graph) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 33, in changes changes = self._detect_changes() File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 62, in _detect_changes if not new_apps.get_model(al, mn)._meta.proxy File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/apps/registry.py", line 183, in get_model return self.get_app_config(app_label).get_model(model_name.lower()) File "/Users/gabejackson/venv/hvad-test/lib/python2.7/site-packages/django/apps/base.py", line 125, in get_model "App '%s' doesn't have a '%s' model." % (self.label, model_name)) LookupError: App 'langapp' doesn't have a 'mymodela' model.
given the following models.py:
from django.db import models from hvad.models import TranslatableModel, TranslatedFields class MyMixin(object): pass # Fails class MyModelA(TranslatableModel, MyMixin): translations = TranslatedFields( name=models.CharField(max_length=60), ) # Works class MyModelB(TranslatableModel): translations = TranslatedFields( name=models.CharField(max_length=60), ) # Works class MyModelC(models.Model, MyMixin): name=models.CharField(max_length=60), # Works obviously class MyModelD(models.Model): name=models.CharField(max_length=60),
Removing MyMixin from MyModelA and re-running migrate works (deleted the sqlite db first):
Operations to perform: Synchronize unmigrated apps: admin, contenttypes, langapp, auth, sessions Apply all migrations: (none) Synchronizing apps without migrations: Creating tables... Creating table django_admin_log Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session Creating table langapp_mymodela_translation Creating table langapp_mymodela Creating table langapp_mymodelb_translation Creating table langapp_mymodelb Creating table langapp_mymodelc Creating table langapp_mymodeld Installing custom SQL... Installing indexes... Installed 0 object(s) from 0 fixture(s) Running migrations: No migrations needed. You have installed Django's auth system, and don't have any superusers defined. Would you like to create one now? (yes/no): no
These tests have been conducted with hvad master (github) and django master (github)
Change History (6)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 11 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
I also ran across a similar issue but didn't distill it to a simple example like Gabe has done.
comment:4 by , 11 years ago
I can't replicate this, as django-hvad doesn't work against 1.7 trunk. Can it be reduced to something that doesn't depend on an external app?
comment:5 by , 11 years ago
Nevermind, I managed to get it working enough to debug the issue - migrations ignores any abstract bases (which TranslatableModel is one of), and if there's no bases at all adds models.Model as a base, but if you had a mixin it had bases but none were from Model. I've pushed a fix.
Looking at the hvad code, I wouldn't be surprised if it needs other updates for 1.7 as it's doing some weird things with models, but that's to be expected, I guess. It at least doesn't immediately fail now.
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
posted after discussion with andrewgodwin in #django-dev
some thoughts: