Opened 4 years ago

Closed 4 years ago

#22764 closed Bug (fixed)

Unable to access ManyToManyField created duration migration

Reported by: M.Meyer@… Owned by: nobody
Component: Migrations Version: 1.7-beta-2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Steps to recreated

  1. Create a new empty project with two models.
  2. Create a migration to add a ManyToManyField
  3. Create another migration to access the new field and it does not exist.
  4. Run the migration again and it works fine.

I've attached a project that will create the error.

Attachments (1)

migration_bug.tgz (9.4 KB) - added by Matthew Meyer <M.Meyer@…> 4 years ago.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by Matthew Meyer <M.Meyer@…>

Attachment: migration_bug.tgz added

comment:1 Changed 4 years ago by Tim Graham

I downloaded the project and ran python migrate without an error. Could you clarify the issue?

comment:2 Changed 4 years ago by Matthew Meyer <M.Meyer@…>

After altering the table the next migration file attempts to access the newly created ManyToManyField and gets the following stack trace.

./ migrate
Operations to perform:
  Synchronize unmigrated apps: admin, contenttypes, auth, sessions
  Apply all migrations: blah
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying blah.0002_auto_20140604_1557... OK
  Applying blah.0003_auto_20140604_1558...Traceback (most recent call last):
  File "./", line 10, in <module>
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/", line 427, in execute_from_command_line
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/", line 419, in execute
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/", line 337, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/commands/", line 146, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/migrations/", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/migrations/", line 96, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/migrations/", line 107, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/migrations/operations/", line 117, in database_forwards
    self.code(from_state.render(), schema_editor)
  File "/home/vagrant/migration_bug/blah/migrations/", line 10, in test_migration
    print type(t.employees)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/models/fields/", line 1162, in __get__
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/models/fields/", line 807, in __init__
    source_field = through._meta.get_field(source_field_name)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/models/", line 397, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))
django.db.models.fields.FieldDoesNotExist: Team_employees has no field named None

comment:3 Changed 4 years ago by Tim Graham

Can you try with latest stable/1.7.x. The output I get:

Running migrations:
  Applying blah.0002_auto_20140604_1557... OK
  Applying blah.0003_auto_20140604_1558...<class 'django.db.models.fields.related.ManyRelatedManager'>
<class 'django.db.models.fields.related.ManyRelatedManager'>

comment:4 Changed 4 years ago by Baptiste Mispelon

Resolution: fixed
Status: newclosed


I can reproduce the issue on 1.7b2 but as Tim said, it appears to be fixed in the latest stable/1.7.x branch.

Using git bisect, I tracked down the commit that seems to have fixed this and found 33511662ddbff0ca22cf5a0b7fdeca2f6764759f.

Consequently, I'll mark this ticket as fixed.


Note: See TracTickets for help on using tickets.
Back to Top