Database error after upgrade to 2.5 from 2.4.6 #2189

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

Originally created by @deku-m on GitHub (Dec 11, 2018).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.0

After applying the upgrade from 2.4.6 to 2.5.0 with the upgrade script located in Netbox. The website doesnt run anymore and gives the following error:

The complete exception is provided below:
<class 'django.db.utils.ProgrammingError'>
column dcim_rack.status does not exist
LINE 1: ... "dcim_rack"."group_id", "dcim_rack"."tenant_id", "dcim_rack...
^

Steps to Reproduce

Apply upgrade via github repository clone. Then run upgrade.sh.

Expected Behavior

Fully working upgrade after migrations.

Observed Behavior

Failed the upgrade but didnt mentioned failures during upgrade.

Also tried

python3 manage.py makemigrations
No changes detected

python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running migrations:
Applying dcim.0066_cables...Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "dcim_cable" already exists

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

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python3.5/dist-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.5/dist-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.5/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/migrations/operations/models.py", line 91, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 312, in create_model
self.execute(sql, params or None)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "dcim_cable" already exists

Originally created by @deku-m on GitHub (Dec 11, 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.5.2 * NetBox version: 2.5.0 <!-- 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). --> After applying the upgrade from 2.4.6 to 2.5.0 with the upgrade script located in Netbox. The website doesnt run anymore and gives the following error: The complete exception is provided below: <class 'django.db.utils.ProgrammingError'> column dcim_rack.status does not exist LINE 1: ... "dcim_rack"."group_id", "dcim_rack"."tenant_id", "dcim_rack... ^ ### Steps to Reproduce Apply upgrade via github repository clone. Then run upgrade.sh. <!-- What did you expect to happen? --> ### Expected Behavior Fully working upgrade after migrations. <!-- What happened instead? --> ### Observed Behavior Failed the upgrade but didnt mentioned failures during upgrade. ## Also tried python3 manage.py makemigrations No changes detected python3 manage.py migrate Operations to perform: Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization Running migrations: Applying dcim.0066_cables...Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) psycopg2.ProgrammingError: relation "dcim_cable" already exists The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 203, in handle fake_initial=fake_initial, File "/usr/local/lib/python3.5/dist-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.5/dist-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.5/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/migrations/operations/models.py", line 91, in database_forwards schema_editor.create_model(model) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 312, in create_model self.execute(sql, params or None) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 133, in execute cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: relation "dcim_cable" already exists
adam closed this issue 2025-12-29 17:23:09 +01:00
Author
Owner

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

Also tried to delete the database, restore data and after do a new migrations but keeps getting a failure.

@deku-m commented on GitHub (Dec 11, 2018): Also tried to delete the database, restore data and after do a new migrations but keeps getting a failure.
Author
Owner

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

Have you made any changes to the database schema? Also, please post the output of python3 manage.py migrate -v 3 from the original v2.4.6 installation so that we can see exactly where the migration is failing.

@jeremystretch commented on GitHub (Dec 11, 2018): Have you made any changes to the database schema? Also, please post the output of `python3 manage.py migrate -v 3` from the original v2.4.6 installation so that we can see exactly where the migration is failing.
Author
Owner

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

As the installation is already on 2.5 i cant rollback anymore. Got the output from setup see below.
Cant see the mention of the error in the webpage:
<class 'django.db.utils.ProgrammingError'>
column dcim_rack.status does not exist
LINE 1: ... "dcim_rack"."group_id", "dcim_rack"."tenant_id", "dcim_rack...
^

Output:
root@pllnx001:/opt/netbox/netbox/netbox# python3 manage.py migrate -v 3
Operations to perform:
Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization
Running pre-migrate handlers for application admin
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application corsheaders
Running pre-migrate handlers for application django_filters
Running pre-migrate handlers for application mptt
Running pre-migrate handlers for application taggit
Running pre-migrate handlers for application timezone_field
Running pre-migrate handlers for application circuits
Running pre-migrate handlers for application dcim
Running pre-migrate handlers for application ipam
Running pre-migrate handlers for application extras
Running pre-migrate handlers for application secrets
Running pre-migrate handlers for application tenancy
Running pre-migrate handlers for application users
Running pre-migrate handlers for application utilities
Running pre-migrate handlers for application virtualization
Running migrations:
Applying dcim.0066_cables...Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "dcim_cable" already exists

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

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File "/usr/local/lib/python3.5/dist-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.5/dist-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.5/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/migrations/operations/models.py", line 91, in database_forwards
schema_editor.create_model(model)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 312, in create_model
self.execute(sql, params or None)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "dcim_cable" already exists

@deku-m commented on GitHub (Dec 11, 2018): As the installation is already on 2.5 i cant rollback anymore. Got the output from setup see below. **Cant see the mention of the error in the webpage:** <class 'django.db.utils.ProgrammingError'> column dcim_rack.status does not exist LINE 1: ... "dcim_rack"."group_id", "dcim_rack"."tenant_id", "dcim_rack... ^ **Output:** root@pllnx001:/opt/netbox/netbox/netbox# python3 manage.py migrate -v 3 Operations to perform: Apply all migrations: admin, auth, circuits, contenttypes, dcim, extras, ipam, secrets, sessions, taggit, tenancy, users, virtualization Running pre-migrate handlers for application admin Running pre-migrate handlers for application auth Running pre-migrate handlers for application contenttypes Running pre-migrate handlers for application sessions Running pre-migrate handlers for application corsheaders Running pre-migrate handlers for application django_filters Running pre-migrate handlers for application mptt Running pre-migrate handlers for application taggit Running pre-migrate handlers for application timezone_field Running pre-migrate handlers for application circuits Running pre-migrate handlers for application dcim Running pre-migrate handlers for application ipam Running pre-migrate handlers for application extras Running pre-migrate handlers for application secrets Running pre-migrate handlers for application tenancy Running pre-migrate handlers for application users Running pre-migrate handlers for application utilities Running pre-migrate handlers for application virtualization Running migrations: Applying dcim.0066_cables...Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) psycopg2.ProgrammingError: relation "dcim_cable" already exists The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 203, in handle fake_initial=fake_initial, File "/usr/local/lib/python3.5/dist-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.5/dist-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.5/dist-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/migrations/operations/models.py", line 91, in database_forwards schema_editor.create_model(model) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 312, in create_model self.execute(sql, params or None) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/base/schema.py", line 133, in execute cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-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.5/dist-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: relation "dcim_cable" already exists
Author
Owner

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

I don't know what you've done up to this point but it seems that your database is corrupt. You'll need to restore a backup from v2.4 and try again. As this is not a reproducible issue, I'm going to close it out. Please post to the mailing list for further assistance once you've restored a known-good database from v2.4.

@jeremystretch commented on GitHub (Dec 11, 2018): I don't know what you've done up to this point but it seems that your database is corrupt. You'll need to restore a backup from v2.4 and try again. As this is not a reproducible issue, I'm going to close it out. Please post to the [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss) for further assistance once you've restored a known-good database from v2.4.
Author
Owner

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

Deleted the previous comment as the "fix" provided will absolutely destroy your database. Never fake schema migrations unless you absolutely understand and can explain in detail what you're doing.

@jeremystretch commented on GitHub (Dec 19, 2018): Deleted the previous comment as the "fix" provided will absolutely destroy your database. **Never fake schema migrations** unless you absolutely understand and can explain in detail what you're doing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2189