Opened 6 years ago
Last modified 6 years ago
#30035 closed Bug
many to many through table not recognisable in custom migration — at Version 1
Reported by: | Mayank Jain | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 2.0 |
Severity: | Normal | Keywords: | many to many, through |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I have a model A
having field b
as many to many. I wanted to make b
default through table's default id field to be UUID.
If I do that using through table, the admin interface changes to Inline and I don't want that. So, I tried writing a custom migration to do that.
If I am checking the default intermediate table using apps.get_model
it exists but when I use the same table in migrations it gives me error:
File "./manage.py", line 19, in <module> execute_from_command_line(sys.argv) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/Users/mj/.virtualenvs/ proj/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute output = self.handle(*args, **options) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle fake_initial=fake_initial, File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/db/migrations/migration.py", line 112, in apply operation.state_forwards(self.app_label, project_state) File "/Users/mj/.virtualenvs/proj/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 70, in state_forwards state.models[app_label, self.model_name_lower].fields.append((self.name, field)) KeyError: ('app', 'A_b')
Note:
See TracTickets
for help on using tickets.