Migration Wrong Number of Constraints #5942

Closed
opened 2025-12-29 19:34:32 +01:00 by adam · 7 comments
Owner

Originally created by @kvedder-amplex on GitHub (Jan 13, 2022).

NetBox version

3.1.5

Python version

3.9

Steps to Reproduce

Do migrations on upgrade from 3.0.7 to 3.1.5

Expected Behavior

The migration should succeed.

Observed Behavior

Running migrations:
Applying circuits.0003_extend_tag_support... OK
Applying circuits.0004_rename_cable_peer... OK
Applying tenancy.0003_contacts... OK
Applying tenancy.0004_extend_tag_support... OK
Applying ipam.0051_extend_tag_support... OK
Applying extras.0063_webhook_conditions... OK
Applying extras.0064_configrevision... OK
Applying ipam.0052_fhrpgroup... OK
Applying ipam.0053_asn_model... OK
Applying dcim.0134_interface_wwn_bridge... OK
Applying dcim.0135_tenancy_extensions... OK
Applying dcim.0136_device_airflow... OK
Applying dcim.0137_relax_uniqueness_constraints...Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/init.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "/opt/netbox/venv/lib/python3.8/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 "/opt/netbox/venv/lib/python3.8/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 "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 126, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/operations/models.py", line 528, in database_forwards
alter_together(
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 415, in alter_unique_together
self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique)
File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 451, in _delete_composed_index
raise ValueError("Found wrong number (%s) of constraints for %s(%s)" % (
ValueError: Found wrong number (2) of constraints for dcim_location(site_id, name)

Originally created by @kvedder-amplex on GitHub (Jan 13, 2022). ### NetBox version 3.1.5 ### Python version 3.9 ### Steps to Reproduce Do migrations on upgrade from 3.0.7 to 3.1.5 ### Expected Behavior The migration should succeed. ### Observed Behavior Running migrations: Applying circuits.0003_extend_tag_support... OK Applying circuits.0004_rename_cable_peer... OK Applying tenancy.0003_contacts... OK Applying tenancy.0004_extend_tag_support... OK Applying ipam.0051_extend_tag_support... OK Applying extras.0063_webhook_conditions... OK Applying extras.0064_configrevision... OK Applying ipam.0052_fhrpgroup... OK Applying ipam.0053_asn_model... OK Applying dcim.0134_interface_wwn_bridge... OK Applying dcim.0135_tenancy_extensions... OK Applying dcim.0136_device_airflow... OK Applying dcim.0137_relax_uniqueness_constraints...Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped res = handle_func(*args, **kwargs) File "/opt/netbox/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle post_migrate_state = executor.migrate( File "/opt/netbox/venv/lib/python3.8/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 "/opt/netbox/venv/lib/python3.8/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 "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 227, in apply_migration state = migration.apply(state, schema_editor) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 126, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/migrations/operations/models.py", line 528, in database_forwards alter_together( File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 415, in alter_unique_together self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) File "/opt/netbox/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 451, in _delete_composed_index raise ValueError("Found wrong number (%s) of constraints for %s(%s)" % ( ValueError: Found wrong number (2) of constraints for dcim_location(site_id, name)
adam closed this issue 2025-12-29 19:34:32 +01:00
Author
Owner

@kvedder-amplex commented on GitHub (Jan 13, 2022):

image

@kvedder-amplex commented on GitHub (Jan 13, 2022): ![image](https://user-images.githubusercontent.com/44881775/149414237-1af8ea44-6c32-4713-ba1e-1549da04befd.png)
Author
Owner

@jeremystretch commented on GitHub (Jan 13, 2022):

Have you verified this starting with a clean install of v3.0.7?

@jeremystretch commented on GitHub (Jan 13, 2022): Have you verified this starting with a clean install of v3.0.7?
Author
Owner

@kvedder-amplex commented on GitHub (Jan 13, 2022):

I will do that right now.

@kvedder-amplex commented on GitHub (Jan 13, 2022): I will do that right now.
Author
Owner

@kvedder-amplex commented on GitHub (Jan 13, 2022):

Bah, it works fine with an empty database.
Is there a manual change I can make to correct this or am I stuck reloading my entire database from scratch?

@kvedder-amplex commented on GitHub (Jan 13, 2022): Bah, it works fine with an empty database. Is there a manual change I can make to correct this or am I stuck reloading my entire database from scratch?
Author
Owner

@jeremystretch commented on GitHub (Jan 13, 2022):

Should be easy enough to fix, assuming something hasn't corrupted the database. If you compare the constraints present on your database to those installed on the stock v3.0.7 deployment, do you see any differences?

@jeremystretch commented on GitHub (Jan 13, 2022): Should be easy enough to fix, assuming something hasn't corrupted the database. If you compare the constraints present on your database to those installed on the stock v3.0.7 deployment, do you see any differences?
Author
Owner

@jeremystretch commented on GitHub (Jan 14, 2022):

I'm going to close this issue as it doesn't seem to be reproducible. However, if you'd still like assistance troubleshooting this, please feel welcome to open a discussion.

@jeremystretch commented on GitHub (Jan 14, 2022): I'm going to close this issue as it doesn't seem to be reproducible. However, if you'd still like assistance troubleshooting this, please feel welcome to open a [discussion](https://github.com/netbox-community/netbox/discussions/new).
Author
Owner

@kvedder-amplex commented on GitHub (Jan 14, 2022):

Thanks Jeremy. Appreciate it.

@kvedder-amplex commented on GitHub (Jan 14, 2022): Thanks Jeremy. Appreciate it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5942