Update to 2.5 fails #2216

Closed
opened 2025-12-29 17:23:40 +01:00 by adam · 6 comments
Owner

Originally created by @tobzsc on GitHub (Dec 15, 2018).

Environment

  • Python version: 3.6.6
  • NetBox version: 2.5

Steps to Reproduce

I am upgrading from 2.4.9 to 2.5

Expected Behavior

Working netbox 2.5

Observed Behavior

Got the following error during upgrade:

Operations to perform:
  Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running migrations:
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying dcim.0064_remove_platform_rpc_client... OK
  Applying dcim.0065_front_rear_ports... OK
  Applying dcim.0066_cables...
    Adding console connections... 0 cables created
    Adding power connections... 60 cables created
    Adding interface connections... Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key"
DETAIL:  Key (_connected_interface_id)=(31574) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "/usr/local/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 "/usr/local/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 "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/opt/netbox/netbox/dcim/migrations/0066_cables.py", line 127, in interface_connections_to_cables
    cable=cable
  File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 693, in update
    rows = query.get_compiler(self.db).execute_sql(CURSOR)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1383, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key"
DETAIL:  Key (_connected_interface_id)=(31574) already exists.

Collecting static files (python3.6 netbox/manage.py collectstatic --no-input)...

202 static files copied to '/opt/netbox/netbox/static', 78 unmodified.
Originally created by @tobzsc on GitHub (Dec 15, 2018). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.6 <!-- Example: 3.6.6 --> * NetBox version: 2.5 <!-- Example: 2.3.6 --> <!-- Describe in detail the steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). --> ### Steps to Reproduce I am upgrading from 2.4.9 to 2.5 <!-- What did you expect to happen? --> ### Expected Behavior Working netbox 2.5 <!-- What happened instead? --> ### Observed Behavior Got the following error during upgrade: ``` Operations to perform: Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization Running migrations: Applying admin.0003_logentry_add_action_flag_choices... OK Applying dcim.0064_remove_platform_rpc_client... OK Applying dcim.0065_front_rear_ports... OK Applying dcim.0066_cables... Adding console connections... 0 cables created Adding power connections... 60 cables created Adding interface connections... Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) psycopg2.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key" DETAIL: Key (_connected_interface_id)=(31574) already exists. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle fake_initial=fake_initial, File "/usr/local/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 "/usr/local/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 "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/usr/local/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/usr/local/lib/python3.6/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards self.code(from_state.apps, schema_editor) File "/opt/netbox/netbox/dcim/migrations/0066_cables.py", line 127, in interface_connections_to_cables cable=cable File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 693, in update rows = query.get_compiler(self.db).execute_sql(CURSOR) File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1383, in execute_sql cursor = super().execute_sql(result_type) File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) django.db.utils.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key" DETAIL: Key (_connected_interface_id)=(31574) already exists. Collecting static files (python3.6 netbox/manage.py collectstatic --no-input)... 202 static files copied to '/opt/netbox/netbox/static', 78 unmodified. ```
adam closed this issue 2025-12-29 17:23:41 +01:00
Author
Owner

@linasjan commented on GitHub (Dec 17, 2018):

Same here.

@linasjan commented on GitHub (Dec 17, 2018): Same here.
Author
Owner

@deku-m commented on GitHub (Dec 17, 2018):

Some one posted a "fix" in the following. https://github.com/digitalocean/netbox/issues/2664 looks almost the same. Didn't test it as I went back to 2.4.6 but maybe it helps.

@deku-m commented on GitHub (Dec 17, 2018): Some one posted a "fix" in the following. https://github.com/digitalocean/netbox/issues/2664 looks almost the same. Didn't test it as I went back to 2.4.6 but maybe it helps.
Author
Owner

@kmiller7851 commented on GitHub (Dec 17, 2018):

Your issues may be related to #2514 . Check your interface with the pk 31574 ( aka find whatever device/interface is at https://netbox.yourdomain.com/dcim/interfaces/31574/ ), then do a lookup for it in both interface connections and circuits to see if there are any duplicates . I'm betting it has either 2 interface connections attached to it, or one connection and one circuit. You'll want to remove the duplicate so the cable migrations in v2.5 can successfully create the cables.

@kmiller7851 commented on GitHub (Dec 17, 2018): Your issues may be related to #2514 . Check your interface with the pk 31574 ( aka find whatever device/interface is at https://netbox.yourdomain.com/dcim/interfaces/31574/ ), then do a lookup for it in both interface connections and circuits to see if there are any duplicates . I'm betting it has either 2 interface connections attached to it, or one connection and one circuit. You'll want to remove the duplicate so the cable migrations in v2.5 can successfully create the cables.
Author
Owner

@tobzsc commented on GitHub (Dec 18, 2018):

Good idea, but that did not do the trick. There was no duplicate interface connection or circuit. :(

@tobzsc commented on GitHub (Dec 18, 2018): Good idea, but that did not do the trick. There was no duplicate interface connection or circuit. :(
Author
Owner

@jeremystretch commented on GitHub (Dec 19, 2018):

psycopg2.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key"
DETAIL:  Key (_connected_interface_id)=(31574) already exists.

This error indicates that your current database has two connections to the same interface. To fix this, first run NetBox v2.4 and go to /dcim/interfaces/31574/. Note and remove the connection to this interface. After deleting the connection, you should see a new connection (the duplicate) appear. Then, make a backup copy of the database, switch to the v2.5 code, and attempt to apply the migrations again.

You may have to repeat this process for each offending duplicate connection.

@jeremystretch commented on GitHub (Dec 19, 2018): ``` psycopg2.IntegrityError: duplicate key value violates unique constraint "dcim_interface__connected_interface_id_key" DETAIL: Key (_connected_interface_id)=(31574) already exists. ``` This error indicates that your current database has two connections to the same interface. To fix this, first run NetBox v2.4 and go to `/dcim/interfaces/31574/`. Note and remove the connection to this interface. After deleting the connection, you should see a new connection (the duplicate) appear. Then, **make a backup copy of the database**, switch to the v2.5 code, and attempt to apply the migrations again. You may have to repeat this process for each offending duplicate connection.
Author
Owner

@tobzsc commented on GitHub (Dec 20, 2018):

Ok, I had two duplicates. That did the trick. @jeremystretch thanks a lot.

@tobzsc commented on GitHub (Dec 20, 2018): Ok, I had two duplicates. That did the trick. @jeremystretch thanks a lot.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2216