#22875: "ValueError: Lookup failed for model referenced by field
app.Model.m2mfield: app.ThroghModel" in simple-self contained M2M setup
--------------------------------------+----------------------------
               Reporter:  ramiro      |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  Migrations  |        Version:  1.7-beta-2
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+----------------------------
 In a simple `ManyToManyField` with intermediate model setup involving
 three models in the same application:

 {{{
 # app_b/models.py
 from django.db import models

 class Employee(models.Model):
     name = models.CharField(max_length=30)

 class Employer(models.Model):
     name = models.CharField(max_length=30)
     employees = models.ManyToManyField(Employee, through='Employment')

 class Employment(models.Model):
     employee = models.ForeignKey(Employee)
     employer = models.ForeignKey(Employer)
     recruiting_date = models.DateField()
 }}}

 I'm seeing the following traceback when running `migrate` after the
 initial migration has been created for the app:

 {{{
 ~/dtest/dtest002$ rm -rf db.sqlite3 app_b/migrations

 ~/dtest/dtest002$ PYTHONPATH=~/django/upstream python ./manage.py
 makemigrations
 No changes detected

 ramiro@serverid:~/dtest/dtest002$ PYTHONPATH=~/django/upstream python
 ./manage.py makemigrations app_b
 Migrations for 'app_b':
   0001_initial.py:
     - Create model Employee
     - Create model Employer
     - Create model Employment

 ~/dtest/dtest002$ PYTHONPATH=~/django/upstream python ./manage.py migrate
 Operations to perform:
   Synchronize unmigrated apps: (none)
   Apply all migrations: admin, contenttypes, app_b, auth, sessions
 Synchronizing apps without migrations:
   Creating tables...
   Installing custom SQL...
   Installing indexes...
 Running migrations:
   Applying contenttypes.0001_initial... OK
   Applying auth.0001_initial... OK
   Applying admin.0001_initial... OK
   Applying app_b.0001_initial...Traceback (most recent call last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "/home/xxx/django/upstream/django/core/management/__init__.py",
 line 385, in execute_from_command_line
     utility.execute()
   File "/home/xxx/django/upstream/django/core/management/__init__.py",
 line 377, in execute
     self.fetch_command(subcommand).run_from_argv(self.argv)
   File "/home/xxx/django/upstream/django/core/management/base.py", line
 288, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/xxx/django/upstream/django/core/management/base.py", line
 337, in execute
     output = self.handle(*args, **options)
   File
 "/home/xxx/django/upstream/django/core/management/commands/migrate.py",
 line 146, in handle
     executor.migrate(targets, plan, fake=options.get("fake", False))
   File "/home/xxx/django/upstream/django/db/migrations/executor.py", line
 62, in migrate
     self.apply_migration(migration, fake=fake)
   File "/home/xxx/django/upstream/django/db/migrations/executor.py", line
 96, in apply_migration
     migration.apply(project_state, schema_editor)
   File "/home/xxx/django/upstream/django/db/migrations/migration.py", line
 107, in apply
     operation.database_forwards(self.app_label, schema_editor,
 project_state, new_state)
   File
 "/home/xxx/django/upstream/django/db/migrations/operations/models.py",
 line 33, in database_forwards
     apps = to_state.render()
   File "/home/xxx/django/upstream/django/db/migrations/state.py", line 89,
 in render
     model=lookup_model,
 ValueError: Lookup failed for model referenced by field
 app_b.Employer.employees: app_b.Employment
 }}}

 I'm selecting '1.7/beta-2' as Version but I'm running the latest
 `stable/1.7.x` code:

 {{{
 ~/django/upstream$ git log  -1
 commit 30d8b95139a1fa3070f3b112115e624ffcf8e555
 Author: Tim Graham <[email protected]>
 Date:   Thu Jun 19 11:02:53 2014 -0400

     [1.7.x] Added feature for implied null (needed for Firebird backend)

     Backport of 1b07781292 from master
 }}}

 Initially Employee didn't exist and the m2m relationship was against a
 custom User model.

 After that trying to create a minimal setup that reproduces the issue,
 usage of the swappable user model feature was removed and the m2m field
 was re-pointed to standard auth.User, and finally to a local Employee
 model.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22875>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.f10a9e00beb22fa0a78f3a69e6e5bf88%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to