Opened 7 years ago

Closed 7 years ago

#28243 closed Bug (duplicate)

Renaming Base model in multi-table inheritance raises django.core.exceptions.FieldError: Auto-generated field clashes

Reported by: Shailesh Ahuja Owned by: nobody
Component: Migrations Version: 1.11
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

Simple test case to demonstrate this issue:

models.py

class A(models.Model):
    pass

class B(A):
    pass

Run makemigrations, and migrate

Change models.py

class A2(models.Model):
    pass

class B(A2):
    pass

Run makemigrations:

   Did you rename the main.A model to A2? [y/N] y
   Did you rename b.a_ptr to b.a2_ptr (a OneToOneField)? [y/N] y

Run migrate:

  Applying main.0002_auto_20170526_0825...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "<path to virtual env>/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "<path to virtual env>/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "<path to virtual env>/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "<path to virtual env>/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "<path to virtual env>/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/migration.py", line 119, in apply
    operation.state_forwards(self.app_label, project_state)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 337, in state_forwards
    state.reload_models(to_reload, delay=True)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/state.py", line 173, in reload_models
    self._reload(related_models)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/state.py", line 199, in _reload
    self.apps.render_multiple(states_to_be_rendered)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/state.py", line 323, in render_multiple
    model.render(self)
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/migrations/state.py", line 626, in render
    body,
  File "<path to virtual env>/lib/python2.7/site-packages/django/db/models/base.py", line 259, in __new__
    base.__name__,
django.core.exceptions.FieldError: Auto-generated field 'a_ptr' in class 'B' for parent_link to base class 'A' clashes with declared field of the same name.

Change History (1)

comment:1 by Tim Graham, 7 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #26488 (the error changed after ecd625e830ef765d5e60d5db7bc6e3b7ffc76d06).

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