Migrating to 2.4.0+ dcim 0058_relax_rack_naming_constraints - Found wrong number of constraints #1983

Closed
opened 2025-12-29 17:21:08 +01:00 by adam · 1 comment
Owner

Originally created by @mryauch on GitHub (Aug 30, 2018).

Python version: 3.6 (Alpine Docker image)
NetBox: Upgrading from 2.3.7 to 2.4.0+. The errors below are pulled from an upgrade attempt to 2.4.0, however every version I have tried past 2.4.0 breaks at the same migration step.
Environment is based on the ninech Docker build. I have upgraded multiple versions previously without issues.

Taking my database from 2.3.7 and following the upgrade procedures results in an error on migration before starting NetBox back up. I have posted to the mailing list and have not resolved the issue. I am unfamiliar with Django and how the migrations/database really work, so I'm not positive if the error is occurring because the database somehow got mangled or if it's some other problem.

Please let me know if there's any further information I can provide to resolve this. I'm currently stuck in time at v2.3.7 and can't move forward. Thank you.

Manually attempting to run migration dcim 0058_relax_rack_naming_constraints results in the following:

bash-4.4# ./manage.py migrate dcim 0058_relax_rack_naming_constraints
Operations to perform:
  Target specific migration: 0058_relax_rack_naming_constraints, from dcim
Running migrations:
  Applying dcim.0058_relax_rack_naming_constraints...Traceback (most recent call last):
  File "./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 371, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, 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 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, 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 122, 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/models.py", line 525, in database_forwards
    getattr(new_model._meta, self.option_name, set()),
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 358, in alter_unique_together
    self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
  File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 387, in _delete_composed_index
    ", ".join(columns),
ValueError: Found wrong number (2) of constraints for dcim_rack(site_id, name)

Here's the list of currently applied migrations:

bash-4.4# ./manage.py showmigrations
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
circuits
 [X] 0001_initial_squashed_0010_circuit_status (10 squashed migrations)
 [X] 0011_tags
 [X] 0012_change_logging
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
dcim
 [X] 0001_initial
 [X] 0002_auto_20160622_1821_squashed_0022_color_names_to_rgb (21 squashed migrations)
 [X] 0023_devicetype_comments_squashed_0043_device_component_name_lengths (21 squashed migrations)
 [X] 0044_virtualization_squashed_0055_virtualchassis_ordering (12 squashed migrations)
 [X] 0056_django2
 [X] 0057_tags
 [ ] 0058_relax_rack_naming_constraints
 [ ] 0059_site_latitude_longitude
 [ ] 0060_change_logging
 [ ] 0061_platform_napalm_args
extras
 [X] 0001_initial_squashed_0010_customfield_filter_logic (10 squashed migrations)
 [ ] 0011_django2
 [ ] 0012_webhooks
 [ ] 0013_objectchange
 [ ] 0014_configcontexts
ipam
 [X] 0001_initial
 [X] 0002_vrf_add_enforce_unique_squashed_0018_remove_service_uniqueness_constraint (17 squashed migrations)
 [X] 0019_virtualization_squashed_0020_ipaddress_add_role_carp (2 squashed migrations)
 [X] 0021_vrf_ordering
 [ ] 0022_tags
 [ ] 0023_change_logging
secrets
 [X] 0001_initial_squashed_0003_unicode_literals (3 squashed migrations)
 [ ] 0004_tags
 [ ] 0005_change_logging
sessions
 [X] 0001_initial
taggit
 [X] 0001_initial
 [X] 0002_auto_20150616_2121
tenancy
 [X] 0001_initial
 [X] 0002_tenant_group_optional_squashed_0003_unicode_literals (2 squashed migrations)
 [ ] 0004_tags
 [ ] 0005_change_logging
users
 [X] 0001_api_tokens_squashed_0002_unicode_literals (2 squashed migrations)
virtualization
 [X] 0001_virtualization
 [X] 0002_virtualmachine_add_status_squashed_0004_virtualmachine_add_role (3 squashed migrations)
 [ ] 0005_django2
 [ ] 0006_tags
 [ ] 0007_change_logging
bash-4.4#

And the current layout in my database for the dcim_rack table:

netbox=> \d dcim_rack
                                     Table "public.dcim_rack"
    Column    |           Type           |                       Modifiers
--------------+--------------------------+--------------------------------------------------------
 id           | integer                  | not null default nextval('dcim_rack_id_seq'::regclass)
 created      | date                     | not null
 last_updated | timestamp with time zone | not null
 name         | character varying(50)    | not null
 facility_id  | character varying(50)    |
 u_height     | smallint                 | not null
 comments     | text                     | not null
 group_id     | integer                  |
 site_id      | integer                  | not null
 tenant_id    | integer                  |
 type         | smallint                 |
 width        | smallint                 | not null
 role_id      | integer                  |
 desc_units   | boolean                  | not null
 serial       | character varying(50)    | not null
Indexes:
    "dcim_rack_pkey" PRIMARY KEY, btree (id)
    "dcim_rack_site_id_2a1d0860_uniq" UNIQUE CONSTRAINT, btree (site_id, facility_id)
    "dcim_rack_site_id_5fde0119_uniq" UNIQUE CONSTRAINT, btree (site_id, name)
    "dcim_rack_site_id_facility_id_2a1d0860_uniq" UNIQUE CONSTRAINT, btree (site_id, facility_id)
    "dcim_rack_site_id_name_5fde0119_uniq" UNIQUE CONSTRAINT, btree (site_id, name)
    "dcim_rack_0e939a4f" btree (group_id)
    "dcim_rack_38543614" btree (tenant_id)
    "dcim_rack_84566833" btree (role_id)
    "dcim_rack_9365d6e7" btree (site_id)
    "dcim_rack_group_id_44e90ea9" btree (group_id)
    "dcim_rack_role_id_62d6919e" btree (role_id)
    "dcim_rack_site_id_403c7b3a" btree (site_id)
    "dcim_rack_tenant_id_7cdf3725" btree (tenant_id)
Check constraints:
    "dcim_rack_type_check" CHECK (type >= 0)
    "dcim_rack_u_height_check" CHECK (u_height >= 0)
    "dcim_rack_width_check" CHECK (width >= 0)
Foreign-key constraints:
    "dcim_rack_group_id_44e90ea9_fk_dcim_rackgroup_id" FOREIGN KEY (group_id) REFERENCES dcim_rackgroup(id) DEFERRABLE INITIALLY DEFERRED
    "dcim_rack_role_id_62d6919e_fk_dcim_rackrole_id" FOREIGN KEY (role_id) REFERENCES dcim_rackrole(id) DEFERRABLE INITIALLY DEFERRED
    "dcim_rack_site_id_403c7b3a_fk_dcim_site_id" FOREIGN KEY (site_id) REFERENCES dcim_site(id) DEFERRABLE INITIALLY DEFERRED
    "dcim_rack_tenant_id_7cdf3725_fk_tenancy_tenant_id" FOREIGN KEY (tenant_id) REFERENCES tenancy_tenant(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
    TABLE "dcim_device" CONSTRAINT "dcim_device_rack_id_23bde71f_fk_dcim_rack_id" FOREIGN KEY (rack_id) REFERENCES dcim_rack(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "dcim_rackreservation" CONSTRAINT "dcim_rackreservation_rack_id_1ebbaa9b_fk_dcim_rack_id" FOREIGN KEY (rack_id) REFERENCES dcim_rack(id) DEFERRABLE INITIALLY DEFERRED

netbox=>
Originally created by @mryauch on GitHub (Aug 30, 2018). **Python version:** 3.6 (Alpine Docker image) **NetBox:** Upgrading from 2.3.7 to 2.4.0+. The errors below are pulled from an upgrade attempt to 2.4.0, however every version I have tried past 2.4.0 breaks at the same migration step. Environment is based on the ninech Docker build. I have upgraded multiple versions previously without issues. Taking my database from 2.3.7 and following the upgrade procedures results in an error on migration before starting NetBox back up. I have posted to the mailing list and have not resolved the issue. I am unfamiliar with Django and how the migrations/database really work, so I'm not positive if the error is occurring because the database somehow got mangled or if it's some other problem. Please let me know if there's any further information I can provide to resolve this. I'm currently stuck in time at v2.3.7 and can't move forward. Thank you. **Manually attempting to run migration dcim 0058_relax_rack_naming_constraints results in the following:** ``` bash-4.4# ./manage.py migrate dcim 0058_relax_rack_naming_constraints Operations to perform: Target specific migration: 0058_relax_rack_naming_constraints, from dcim Running migrations: Applying dcim.0058_relax_rack_naming_constraints...Traceback (most recent call last): File "./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 371, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, 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 288, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, 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 122, 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/models.py", line 525, in database_forwards getattr(new_model._meta, self.option_name, set()), File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 358, in alter_unique_together self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 387, in _delete_composed_index ", ".join(columns), ValueError: Found wrong number (2) of constraints for dcim_rack(site_id, name) ``` **Here's the list of currently applied migrations:** ``` bash-4.4# ./manage.py showmigrations admin [X] 0001_initial [X] 0002_logentry_remove_auto_add auth [X] 0001_initial [X] 0002_alter_permission_name_max_length [X] 0003_alter_user_email_max_length [X] 0004_alter_user_username_opts [X] 0005_alter_user_last_login_null [X] 0006_require_contenttypes_0002 [X] 0007_alter_validators_add_error_messages [X] 0008_alter_user_username_max_length [X] 0009_alter_user_last_name_max_length circuits [X] 0001_initial_squashed_0010_circuit_status (10 squashed migrations) [X] 0011_tags [X] 0012_change_logging contenttypes [X] 0001_initial [X] 0002_remove_content_type_name dcim [X] 0001_initial [X] 0002_auto_20160622_1821_squashed_0022_color_names_to_rgb (21 squashed migrations) [X] 0023_devicetype_comments_squashed_0043_device_component_name_lengths (21 squashed migrations) [X] 0044_virtualization_squashed_0055_virtualchassis_ordering (12 squashed migrations) [X] 0056_django2 [X] 0057_tags [ ] 0058_relax_rack_naming_constraints [ ] 0059_site_latitude_longitude [ ] 0060_change_logging [ ] 0061_platform_napalm_args extras [X] 0001_initial_squashed_0010_customfield_filter_logic (10 squashed migrations) [ ] 0011_django2 [ ] 0012_webhooks [ ] 0013_objectchange [ ] 0014_configcontexts ipam [X] 0001_initial [X] 0002_vrf_add_enforce_unique_squashed_0018_remove_service_uniqueness_constraint (17 squashed migrations) [X] 0019_virtualization_squashed_0020_ipaddress_add_role_carp (2 squashed migrations) [X] 0021_vrf_ordering [ ] 0022_tags [ ] 0023_change_logging secrets [X] 0001_initial_squashed_0003_unicode_literals (3 squashed migrations) [ ] 0004_tags [ ] 0005_change_logging sessions [X] 0001_initial taggit [X] 0001_initial [X] 0002_auto_20150616_2121 tenancy [X] 0001_initial [X] 0002_tenant_group_optional_squashed_0003_unicode_literals (2 squashed migrations) [ ] 0004_tags [ ] 0005_change_logging users [X] 0001_api_tokens_squashed_0002_unicode_literals (2 squashed migrations) virtualization [X] 0001_virtualization [X] 0002_virtualmachine_add_status_squashed_0004_virtualmachine_add_role (3 squashed migrations) [ ] 0005_django2 [ ] 0006_tags [ ] 0007_change_logging bash-4.4# ``` **And the current layout in my database for the dcim_rack table:** ``` netbox=> \d dcim_rack Table "public.dcim_rack" Column | Type | Modifiers --------------+--------------------------+-------------------------------------------------------- id | integer | not null default nextval('dcim_rack_id_seq'::regclass) created | date | not null last_updated | timestamp with time zone | not null name | character varying(50) | not null facility_id | character varying(50) | u_height | smallint | not null comments | text | not null group_id | integer | site_id | integer | not null tenant_id | integer | type | smallint | width | smallint | not null role_id | integer | desc_units | boolean | not null serial | character varying(50) | not null Indexes: "dcim_rack_pkey" PRIMARY KEY, btree (id) "dcim_rack_site_id_2a1d0860_uniq" UNIQUE CONSTRAINT, btree (site_id, facility_id) "dcim_rack_site_id_5fde0119_uniq" UNIQUE CONSTRAINT, btree (site_id, name) "dcim_rack_site_id_facility_id_2a1d0860_uniq" UNIQUE CONSTRAINT, btree (site_id, facility_id) "dcim_rack_site_id_name_5fde0119_uniq" UNIQUE CONSTRAINT, btree (site_id, name) "dcim_rack_0e939a4f" btree (group_id) "dcim_rack_38543614" btree (tenant_id) "dcim_rack_84566833" btree (role_id) "dcim_rack_9365d6e7" btree (site_id) "dcim_rack_group_id_44e90ea9" btree (group_id) "dcim_rack_role_id_62d6919e" btree (role_id) "dcim_rack_site_id_403c7b3a" btree (site_id) "dcim_rack_tenant_id_7cdf3725" btree (tenant_id) Check constraints: "dcim_rack_type_check" CHECK (type >= 0) "dcim_rack_u_height_check" CHECK (u_height >= 0) "dcim_rack_width_check" CHECK (width >= 0) Foreign-key constraints: "dcim_rack_group_id_44e90ea9_fk_dcim_rackgroup_id" FOREIGN KEY (group_id) REFERENCES dcim_rackgroup(id) DEFERRABLE INITIALLY DEFERRED "dcim_rack_role_id_62d6919e_fk_dcim_rackrole_id" FOREIGN KEY (role_id) REFERENCES dcim_rackrole(id) DEFERRABLE INITIALLY DEFERRED "dcim_rack_site_id_403c7b3a_fk_dcim_site_id" FOREIGN KEY (site_id) REFERENCES dcim_site(id) DEFERRABLE INITIALLY DEFERRED "dcim_rack_tenant_id_7cdf3725_fk_tenancy_tenant_id" FOREIGN KEY (tenant_id) REFERENCES tenancy_tenant(id) DEFERRABLE INITIALLY DEFERRED Referenced by: TABLE "dcim_device" CONSTRAINT "dcim_device_rack_id_23bde71f_fk_dcim_rack_id" FOREIGN KEY (rack_id) REFERENCES dcim_rack(id) DEFERRABLE INITIALLY DEFERRED TABLE "dcim_rackreservation" CONSTRAINT "dcim_rackreservation_rack_id_1ebbaa9b_fk_dcim_rack_id" FOREIGN KEY (rack_id) REFERENCES dcim_rack(id) DEFERRABLE INITIALLY DEFERRED netbox=> ```
adam closed this issue 2025-12-29 17:21:08 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 5, 2018):

Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using the template provided here. For general discussion, questions, or assistance with installation issues, please post to our mailing list.

@jeremystretch commented on GitHub (Sep 5, 2018): Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using the template provided [here](https://raw.githubusercontent.com/digitalocean/netbox/develop/.github/ISSUE_TEMPLATE.md). For general discussion, questions, or assistance with installation issues, please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1983