Unable to upgrade Netbox from 2.9.7 to 2.10.2/Static Media Failure? #4433

Closed
opened 2025-12-29 18:35:56 +01:00 by adam · 2 comments
Owner

Originally created by @CodyChell on GitHub (Jan 4, 2021).

Environment
Python Version 3.6.9

Netbox version 2.9.7

PostgreSQL version 10.15

OS Ubuntu 18.04.5 LTS

Steps to Reproduce
sudo -u netbox venv/bin/python3 netbox/manage.py migrate
(or using the upgrade.sh)

Expected Behavior

Complete the upgrade and DB migrations.

Observed Behavior

Applying database migrations (python3 netbox/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 extras.0051_migrate_customfields...Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/migrations/0051_migrate_customfields.py", line 28, in migrate_customfield_defaults
    value = int(customfield.default)
ValueError: invalid literal for int() with base 10: 'VM ID listed in hypervisor inventory'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 245, in handle
    fake_initial=fake_initial,
  File "/opt/netbox/venv/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 "/opt/netbox/venv/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 "/opt/netbox/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/opt/netbox/venv/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 "/opt/netbox/venv/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/extras/migrations/0051_migrate_customfields.py", line 35, in migrate_customfield_defaults
    f'Invalid default value "{customfield.default}" found for {customfield.type} '
ValueError: Invalid default value "VM ID listed in hypervisor inventory" found for integer custom field VM_ID

Tried to run this through the ./upgrade.sh script after pulling a new branch. Did also do apt update and upgrade before pulling master branch. Not sure why I am seeing this error.
Netbox is starting, but I am unable to get into the WebUI
This is what I get in the WebUI

mRemoteNG_2021-01-04_14-52-54

Any help would be much appreciated.

Originally created by @CodyChell on GitHub (Jan 4, 2021). **Environment** Python Version 3.6.9 Netbox version 2.9.7 PostgreSQL version 10.15 OS Ubuntu 18.04.5 LTS **Steps to Reproduce** sudo -u netbox venv/bin/python3 netbox/manage.py migrate (or using the upgrade.sh) **Expected Behavior** Complete the upgrade and DB migrations. **Observed Behavior** ``` Applying database migrations (python3 netbox/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 extras.0051_migrate_customfields...Traceback (most recent call last): File "/opt/netbox/netbox/extras/migrations/0051_migrate_customfields.py", line 28, in migrate_customfield_defaults value = int(customfield.default) ValueError: invalid literal for int() with base 10: 'VM ID listed in hypervisor inventory' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv self.execute(*args, **cmd_options) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute output = self.handle(*args, **options) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped res = handle_func(*args, **kwargs) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 245, in handle fake_initial=fake_initial, File "/opt/netbox/venv/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 "/opt/netbox/venv/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 "/opt/netbox/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 227, in apply_migration state = migration.apply(state, schema_editor) File "/opt/netbox/venv/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 "/opt/netbox/venv/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/extras/migrations/0051_migrate_customfields.py", line 35, in migrate_customfield_defaults f'Invalid default value "{customfield.default}" found for {customfield.type} ' ValueError: Invalid default value "VM ID listed in hypervisor inventory" found for integer custom field VM_ID ``` Tried to run this through the ./upgrade.sh script after pulling a new branch. Did also do apt update and upgrade before pulling master branch. Not sure why I am seeing this error. Netbox is starting, but I am unable to get into the WebUI This is what I get in the WebUI ![mRemoteNG_2021-01-04_14-52-54](https://user-images.githubusercontent.com/25127820/103578679-9e24ab00-4e9c-11eb-8dc7-605962408a18.png) Any help would be much appreciated.
adam closed this issue 2025-12-29 18:35:56 +01:00
Author
Owner

@candlerb commented on GitHub (Jan 4, 2021):

"Static media failure" is a red herring - what's happened is that the database migration has failed to complete, due to invalid custom field data, which has stopped upgrade.sh from completing. I had a similar issue in #5573.

Firstly you'll need to revert the database to the backup you took just before the upgrade, so that you can try again from scratch. A partial update will leave your database in a broken state; don't attempt to work from this point forwards.

Then you'll need to manually fix the custom field data in SQL so that it's valid - unfortunately the migrations are picky, and as you've seen, they will barf if anything is wrong. The error message was raised here:

ValueError: Invalid default value "VM ID listed in hypervisor inventory" found for integer custom field VM_ID

That is: you have a custom field called "VM_ID", and you defined this to be an integer, but the default value is a string "VM ID listed in hypervisor inventory". You can set this either to be the empty string (no default), or to a valid integer like 0.

  • Go into postgres: typically sudo -u postgres psql netbox
  • Look for the broken entry: select id,type,name,"default" from extras_customfield;
  • Do a SQL update to correct the broken row(s)
  • Exit postgres

At this point, you can run upgrade.sh again. If it barfs again, check the new error, revert the database again, apply all the old changes plus any new changes required, rinse and repeat.

@candlerb commented on GitHub (Jan 4, 2021): "Static media failure" is a red herring - what's happened is that the database migration has failed to complete, due to invalid custom field data, which has stopped `upgrade.sh` from completing. I had a similar issue in #5573. Firstly you'll need to revert the database to the backup you took just before the upgrade, so that you can try again from scratch. A partial update will leave your database in a broken state; don't attempt to work from this point forwards. Then you'll need to manually fix the custom field data in SQL so that it's valid - unfortunately the migrations are picky, and as you've seen, they will barf if anything is wrong. The error message was raised [here](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/migrations/0051_migrate_customfields.py#L19-L38): ``` ValueError: Invalid default value "VM ID listed in hypervisor inventory" found for integer custom field VM_ID ``` That is: you have a custom field called "VM_ID", and you defined this to be an integer, but the default value is a string "VM ID listed in hypervisor inventory". You can set this either to be the empty string (no default), or to a valid integer like `0`. * Go into postgres: typically `sudo -u postgres psql netbox` * Look for the broken entry: `select id,type,name,"default" from extras_customfield;` * Do a SQL update to correct the broken row(s) * Exit postgres At this point, you can run upgrade.sh again. If it barfs again, check the new error, revert the database again, apply all the old changes *plus* any new changes required, rinse and repeat.
Author
Owner

@DanSheps commented on GitHub (Jan 5, 2021):

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

@DanSheps commented on GitHub (Jan 5, 2021): Thank you for your interest in NetBox. GitHub issues are intended for reporting reproducible bugs and requesting features, and must be submitted using one of the templates provided [here](https://github.com/netbox-community/netbox/issues/new/choose). For general discussion, questions, or assistance with installation issues, please post to the [discussions](https://github.com/netbox-community/netbox/discussions) instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4433