You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're seeing an issue upgrading an existing deployment from Constance 2.9.1 to 4.1.2.
Steps to reproduce
Have a project with database records from 2.9.1 (Constance configs in constance_config database table, migrations run include database 0001_initial and database 0002_auto_20190129_2304
Have apps in the project that attempt to read from the Constance config at startup time (e.g. to determine which app features are administratively enabled)
Upgrade to Constance 4.1.2 and run migrations
04:22:08.517 WARNING nautobot.apps.config :
"PLUGINS_CONFIG['nautobot_chatops']['enable_grafana']" is not in settings, and could not read from the Constance datab
ase table (perhaps not initialized yet?)
...
04:22:17.282 WARNING nautobot.core.utils.config :
Configuration "NETWORK_DRIVERS" is not in settings, and could not read from the Constance database table (perhaps not
initialized yet?)
Performing database migrations...
...
Applying constance.0001_initial... OK
Applying constance.0002_migrate_from_old_table...Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "constance_constance_pkey"
DETAIL: Key (id)=(1) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/bin/nautobot-server", line 8, in <module>
sys.exit(main())
^^^^^^
File "/usr/local/lib/python3.11/site-packages/nautobot/core/cli/__init__.py", line 293, in main
execute_from_command_line([sys.argv[0], *unparsed_args])
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_l
ine
utility.execute()
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/nautobot/core/management/commands/post_upgrade.py", line 91, in handle
call_command(
File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 194, in call_command
return command.execute(*args, **defaults)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle
post_migrate_state = executor.migrate(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
state = self.apply_migration(
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
File "/usr/local/lib/python3.11/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwa
rds
self.code(from_state.apps, schema_editor)
File "/usr/local/lib/python3.11/site-packages/constance/migrations/0002_migrate_from_old_table.py", line 21, in _migra
te_from_old_table
cursor.execute(
File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: duplicate key value violates unique constraint "constance_constance_pkey"
DETAIL: Key (id)=(1) already exists.
Sure enough, somehow the attempt to read the records from constance_constance during app startup has resulted in records being created in this newly initialized table, which are now conflicting with the records that Constance is trying to auto-migrate from constance_config:
All of the records currently showing in constance_constance are settings that apps are attempting to read during application startup, so something (presumably django-constance itself?) resulted in these being written to the database in the middle of running migrations.
System configuration
Django version: 4.2
Python version: 3.11
Django-Constance version: 4.1.2
The text was updated successfully, but these errors were encountered:
Describe the problem
We're seeing an issue upgrading an existing deployment from Constance 2.9.1 to 4.1.2.
Steps to reproduce
constance_config
database table, migrations run includedatabase 0001_initial
anddatabase 0002_auto_20190129_2304
Sure enough, somehow the attempt to read the records from
constance_constance
during app startup has resulted in records being created in this newly initialized table, which are now conflicting with the records that Constance is trying to auto-migrate fromconstance_config
:All of the records currently showing in
constance_constance
are settings that apps are attempting to read during application startup, so something (presumably django-constance itself?) resulted in these being written to the database in the middle of running migrations.System configuration
The text was updated successfully, but these errors were encountered: