migrations don't work

202 views
Skip to first unread message

somen...@gmail.com

unread,
Mar 22, 2015, 2:16:57 PM3/22/15
to django...@googlegroups.com
Hi,

makemigrations works but migrate does not:

[xan@mercuri gargamella]$ python manage.py makemigrations
Migrations for 'quedar':
 
0003_auto_20150322_1813.py:
   
- Create model Persona
   
- Delete model User
   
- Add field user to persona
   
- Alter field members on dialectgroup
   
- Alter field members on languagelevelgroup
   
- Alter field members on learninggroup
   
- Alter field members on learningpeople
   
- Alter field members on teachinggroup
[xan@mercuri gargamella]$ python manage.py migrate
Operations to perform:
 
Apply all migrations: admin, auth, sessions, contenttypes, quedar
Running migrations:
 
Applying quedar.0003_auto_20150322_1813...Traceback (most recent call last):
 
File "/usr/lib/python3.4/site-packages/django/apps/config.py", line 163, in get_model
   
return self.models[model_name.lower()]
KeyError: 'user'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 
File "/usr/lib/python3.4/site-packages/django/db/migrations/state.py", line 84, in render
    model
= self.apps.get_model(lookup_model[0], lookup_model[1])
 
File "/usr/lib/python3.4/site-packages/django/apps/registry.py", line 202, in get_model
   
return self.get_app_config(app_label).get_model(model_name.lower())
 
File "/usr/lib/python3.4/site-packages/django/apps/config.py", line 166, in get_model
   
"App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'quedar' doesn't have a 'user' model.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/lib/python3.4/site-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 29, in database_forwards
    to_model = to_state.render().get_model(app_label, self.model_name)
  File "/usr/lib/python3.4/site-packages/django/db/migrations/state.py", line 94, in render
    raise ValueError(msg.format(field=operations[0][1], model=lookup_model))
ValueError: Lookup failed for model referenced by field quedar.LearningGroup.members: quedar.User
[xan@mercuri gargamella]$



Any hints?

Vijay Khemlani

unread,
Mar 22, 2015, 2:35:11 PM3/22/15
to django...@googlegroups.com
Judging from the makemigrations output, you deleted a model (User) but also added it as a foreignkey field to another model (Persona), is that what you wanted?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/df31034a-8de7-4b25-81b6-fd5d0f954a2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Markus Holtermann

unread,
Mar 22, 2015, 2:46:05 PM3/22/15
to django...@googlegroups.com
Hi,

from the information you provided I can only guess you are migrating away from a custom user model to the "normal" Django user model. This won't work (out of the box). And even the way to migrate from the Django user model to a custom user model is more of a workaround than a solution. Please see https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model for details.

/Markus

James Schneider

unread,
Mar 22, 2015, 3:29:17 PM3/22/15
to django...@googlegroups.com

I think the end of the traceback is pretty telling:

ValueError: Lookup failed for model referenced by field quedar.LearningGroup.members: quedar.User

You have a LearningGroup model with an attribute called members which is still referencing the original User model that was removed.

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages