Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#22488 closed Bug (duplicate)

"ValueError: Lookup failed" on migrate after 1.7b2 upgrade

Reported by: Karen Tracey Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Release blocker Keywords:
Cc: Ben Davis Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm getting an error running migrate on a project after upgrading from 1.7b1 to 1.7b2. Running tests produces same error (somewhat different traceback). Besides the error something weird I notice is that auth is listed in both the "unmigrated" and "migrated" apps...I have no idea why. The project does use a custom user model. auth is listed as both migrated and not for 1.7b1 and 1.7b2, but the error only occurs on 1.7b2.

I am not sure what would be helpful to debug this. This is what I see:

(uncfm) kmtracey@caktus006 11:48:48: ~/projects/uncfm
--> ./manage.py shell
Python 3.3.5 (default, Mar 12 2014, 02:09:17) 
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.get_version()
'1.7b1'
>>> quit()

(uncfm) kmtracey@caktus006 11:48:59: ~/projects/uncfm
--> ./manage.py migrate --list
core
 [X] 0001_initial
m3app
 [X] 0001_initial
 [X] 0002_observer_active
 [X] 0003_auto_20140415_1317
scribbler
 (no migrations)

(uncfm) kmtracey@caktus006 11:49:02: ~/projects/uncfm
--> ./manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: compressor, sitemaps, contenttypes, scribbler, sessions, auth, admin
  Apply all migrations: auth, core, m3app
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations needed.

(uncfm) kmtracey@caktus006 11:49:08: ~/projects/uncfm
--> pip install requirements/sdists/Django-1.7b2.tar.gz 
Unpacking ./requirements/sdists/Django-1.7b2.tar.gz
  Running setup.py (path:/tmp/pip-v_a8yl-build/setup.py) egg_info for package from file:///home/kmtracey/projects/uncfm/requirements/sdists/Django-1.7b2.tar.gz
    
    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: Django
  Found existing installation: Django 1.7b1
    Uninstalling Django:
      Successfully uninstalled Django
  Running setup.py install for Django
    
    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of build/scripts-3.3/django-admin.py from 664 to 775
    changing mode of /home/kmtracey/.virtualenvs/uncfm/bin/django-admin.py to 775
    Installing django-admin script to /home/kmtracey/.virtualenvs/uncfm/bin
Successfully installed Django
Cleaning up...

(uncfm) kmtracey@caktus006 11:49:36: ~/projects/uncfm
--> ./manage.py migrate --list
core
 [X] 0001_initial
m3app
 [X] 0001_initial
 [X] 0002_observer_active
 [X] 0003_auto_20140415_1317
scribbler
 (no migrations)

(uncfm) kmtracey@caktus006 11:49:45: ~/projects/uncfm
--> ./manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: sitemaps, contenttypes, scribbler, auth, compressor, sessions, admin
  Apply all migrations: auth, m3app, core
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations needed.
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/migrate.py", line 140, in handle
    changes = autodetector.changes(graph=executor.loader.graph)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/autodetector.py", line 33, in changes
    changes = self._detect_changes()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/autodetector.py", line 50, in _detect_changes
    old_apps = self.from_state.render()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/state.py", line 63, in render
    model=dangling_lookup[0]))
ValueError: Lookup failed for model referenced by field auth.Permission.content_type: contenttypes.ContentType

(uncfm) kmtracey@caktus006 11:49:52: ~/projects/uncfm
--> ./manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: database "test_uncfm" already exists

Type 'yes' if you would like to try deleting the test database 'test_uncfm', or 'no' to cancel: yes
Destroying old test database 'default'...
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/test/runner.py", line 297, in setup_databases
    verbosity, autoclobber=not interactive)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/backends/creation.py", line 368, in create_test_db
    test_database=True)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/__init__.py", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/core/management/commands/migrate.py", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/executor.py", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/executor.py", line 88, in apply_migration
    if self.detect_soft_applied(migration):
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/executor.py", line 132, in detect_soft_applied
    apps = project_state.render()
  File "/home/kmtracey/.virtualenvs/uncfm/lib/python3.3/site-packages/django/db/migrations/state.py", line 63, in render
    model=dangling_lookup[0]))
ValueError: Lookup failed for model referenced by field auth.Permission.content_type: contenttypes.ContentType

Change History (3)

comment:1 by Simon Charette, 10 years ago

Resolution: duplicate
Status: newclosed

Hi Karen,

This is a duplicate of #22485 which is related to #21968 and #22397.

comment:2 by Ben Davis, 10 years ago

Cc: Ben Davis added

[edit] sorry, just realized this was a dup. I'll post this in the main ticket.

I got this same error when trying to migrate my own app when my project uses he django-taggit app. TaggedItem has a ForeignKey to ContentType, and when trying to makemigrations for one of my apps I get the following:

ValueError: Lookup failed for model referenced by field taggit.TaggedItem.content_type: contenttypes.ContentType

Is there a workaround?

Last edited 10 years ago by Ben Davis (previous) (diff)

in reply to:  2 comment:3 by rockallite.wulf@…, 10 years ago

Replying to bendavis78:

[edit] sorry, just realized this was a dup. I'll post this in the main ticket.

I got this same error when trying to migrate my own app when my project uses he django-taggit app. TaggedItem has a ForeignKey to ContentType, and when trying to makemigrations for one of my apps I get the following:

ValueError: Lookup failed for model referenced by field taggit.TaggedItem.content_type: contenttypes.ContentType

Is there a workaround?

Just add the corresponding dependency in the migration file, like this:

    dependencies = [
        (b'advperm', b'0001_initial'),
        (b'auth', b'__first__'),
        (b'contenttypes', b'__first__'),  # Add this line
    ]
Note: See TracTickets for help on using tickets.
Back to Top