Migration changed name causing migration conflict #11429

Closed
opened 2025-12-29 21:45:08 +01:00 by adam · 0 comments
Owner

Originally created by @arthanson on GitHub (Jul 30, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

feature @ b610cf37cf

Python Version

3.10

Steps to Reproduce

  1. be on main branch and create database with data fully migrated
  2. switch to feature branch and run migrations

Expected Behavior

Migrations should run without error

Observed Behavior

Migrations will fail with the following error:

This is issue is main has 0208_devicerole_uniqueness.py it is renamed in feature as 0210_devicerole_uniqueness.py which causes the migration to be run again and erroring as it has already been completed.

Traceback (most recent call last):
  File "/Users/ahanson/dev/work/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/commands/migrate.py", line 353, in handle
    post_migrate_state = executor.migrate(
        targets,
    ...<3 lines>...
        fake_initial=fake_initial,
    )
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
        state, plan, full_plan, fake=fake, fake_initial=fake_initial
    )
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
        state, migration, fake=fake, fake_initial=fake_initial
    )
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self.app_label, schema_editor, old_state, project_state
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/operations/models.py", line 1211, in database_forwards
    schema_editor.add_constraint(model, self.constraint)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/base/schema.py", line 596, in add_constraint
    self.execute(sql, params=None)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/postgresql/schema.py", line 45, in execute
    return super().execute(sql, params)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/base/schema.py", line 204, in execute
    cursor.execute(sql, params)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        sql, params, many=False, executor=self._execute
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ~~~~~~~~~~~~~~~~~~~^^^^^
  File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "dcim_devicerole_parent_name" already exists
Originally created by @arthanson on GitHub (Jul 30, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version `feature` @ b610cf37cff253e2aa03541782ca328daf9cf123 ### Python Version 3.10 ### Steps to Reproduce 1. be on main branch and create database with data fully migrated 2. switch to feature branch and run migrations ### Expected Behavior Migrations should run without error ### Observed Behavior Migrations will fail with the following error: This is issue is main has 0208_devicerole_uniqueness.py it is renamed in feature as 0210_devicerole_uniqueness.py which causes the migration to be run again and erroring as it has already been completed. ``` Traceback (most recent call last): File "/Users/ahanson/dev/work/netbox/netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() ~~~~~~~~~~~~~~~^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 416, in run_from_argv self.execute(*args, **cmd_options) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 460, in execute output = self.handle(*args, **options) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/base.py", line 107, in wrapper res = handle_func(*args, **kwargs) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/core/management/commands/migrate.py", line 353, in handle post_migrate_state = executor.migrate( targets, ...<3 lines>... fake_initial=fake_initial, ) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( state, plan, full_plan, fake=fake, fake_initial=fake_initial ) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( state, migration, fake=fake, fake_initial=fake_initial ) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 255, in apply_migration state = migration.apply(state, schema_editor) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ self.app_label, schema_editor, old_state, project_state ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/migrations/operations/models.py", line 1211, in database_forwards schema_editor.add_constraint(model, self.constraint) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/base/schema.py", line 596, in add_constraint self.execute(sql, params=None) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/postgresql/schema.py", line 45, in execute return super().execute(sql, params) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/base/schema.py", line 204, in execute cursor.execute(sql, params) ~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 122, in execute return super().execute(sql, params) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 79, in execute return self._execute_with_wrappers( ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ sql, params, many=False, executor=self._execute ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers return executor(sql, params, many, context) File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 100, in _execute with self.db.wrap_database_errors: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/django/db/backends/utils.py", line 103, in _execute return self.cursor.execute(sql) ~~~~~~~~~~~~~~~~~~~^^^^^ File "/Users/ahanson/dev/work/netbox/venv/lib/python3.13/site-packages/psycopg/cursor.py", line 97, in execute raise ex.with_traceback(None) django.db.utils.ProgrammingError: relation "dcim_devicerole_parent_name" already exists ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 21:45:08 +01:00
adam closed this issue 2025-12-29 21:45:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11429