Opened 9 years ago
Last modified 9 years ago
#26564 closed Bug
Migration for renaming M2M field intermediate model causes exception — at Version 1
Reported by: | MohammadJafar MashhadiEbrahim | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
There was Models Service, Application and ServiceActivation. ServiceActivation is intermediate model between Service and Application. I renamed ServiceActivation to ServiceInstance and theses migrations were generated:
migrations.RenameModel( old_name='ServiceActivation', new_name='ServiceInstance', ), migrations.AlterField( model_name='application', name='services', field=models.ManyToManyField(related_name='user_applications', through='core.ServiceInstance', to='core.Service'), ),
I moved two operations to two separate migration files, the second is dependent on the first to ensure that sequence of running is correct. RenameModel operation runs normally but AlterField does not. Stack trace is as the following:
$ python manage.py migrate Operations to perform: Apply all migrations: core Running migrations: Applying core.0008_renamed_service_activation_model_2...Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line utility.execute() File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/raven/contrib/django/management/__init__.py", line 41, in new_execute return original_func(self, *args, **kwargs) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute output = self.handle(*args, **options) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 200, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 92, in migrate self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 198, in apply_migration state = migration.apply(state, schema_editor) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 123, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/home/mjafar/Documents/project/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 465, in alter_field old_field.remote_field.through._meta.auto_created and AttributeError: 'str' object has no attribute '_meta'
I read the code in schema.py around the line number that exception occuress, hoping to find a workaround but unfortunately i couldn't. Updated to Django 1.9.5 but bug still exists.