Opened 10 years ago

Closed 10 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

Description

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@…> 10 years ago.

Download all attachments as: .zip

Change History (5)

by Matthew Meyer <M.Meyer@…>, 10 years ago

Attachment: migration_bug.tgz added

comment:1 by Tim Graham, 10 years ago

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

comment:2 by Matthew Meyer <M.Meyer@…>, 10 years ago

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

./manage.py 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 "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/core/management/base.py", 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/base.py", 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/migrate.py", 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/executor.py", 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/executor.py", 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/migration.py", 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/special.py", line 117, in database_forwards
    self.code(from_state.render(), schema_editor)
  File "/home/vagrant/migration_bug/blah/migrations/0003_auto_20140604_1558.py", 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/related.py", line 1162, in __get__
    through=self.field.rel.through,
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7b4-py2.7.egg/django/db/models/fields/related.py", 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/options.py", 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 by Tim Graham, 10 years ago

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'>
 OK

comment:4 by Baptiste Mispelon, 10 years ago

Resolution: fixed
Status: newclosed

Hi,

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.

Thanks.

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