Migration failure for "extras" from container 3.4.0 -> 3.4.1 / 0133_make_cf_minmax_decimal.py / django.db.utils.DataError: numeric field overflow #11767

Closed
opened 2025-12-29 21:49:38 +01:00 by adam · 5 comments
Owner

Originally created by @amsnek on GitHub (Oct 23, 2025).

NetBox Edition

NetBox Community

NetBox Version

4.4.0 / 4.4.4

Python Version

3.12

Steps to Reproduce

  1. Using the containers from https://github.com/netbox-community/netbox-docker/releases
  2. updating container version from 3.4.0 to 3.4.1
  3. migrations fail on "extras" / "0133_make_cf_minmax_decimal"

Expected Behavior

migrations apply successfully

Observed Behavior

exception:

Operations to perform:
  Apply all migrations: extras
Running migrations:
  Applying extras.0133_make_cf_minmax_decimal...Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
psycopg.errors.NumericValueOutOfRange: numeric field overflow
DETAIL:  A field with precision 16, scale 4 must round to an absolute value less than 10^12.

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

Traceback (most recent call last):
  File "/opt/netbox/netbox/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 353, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 255, in apply_migration
    state = migration.apply(state, schema_editor)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/operations/fields.py", line 241, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 912, in alter_field
    self._alter_field(
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 274, in _alter_field
    super()._alter_field(
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 1165, in _alter_field
    self.execute(
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 48, in execute
    return super().execute(sql, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 204, in execute
    cursor.execute(sql, params)
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.DataError: numeric field overflow
DETAIL:  A field with precision 16, scale 4 must round to an absolute value less than 10^12.
$ cat extras/migrations/0133_make_cf_minmax_decimal.py
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('extras', '0132_configcontextprofile'),
    ]

    operations = [
        migrations.AlterField(
            model_name='customfield',
            name='validation_maximum',
            field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True),
        ),
        migrations.AlterField(
            model_name='customfield',
            name='validation_minimum',
            field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True),
        ),
    ]

to complete the migrations, max_digits=16 -> was modified to: max_digits=300 🙈 . this might not been wise but not sure how else to workaround this issue.

Originally created by @amsnek on GitHub (Oct 23, 2025). ### NetBox Edition NetBox Community ### NetBox Version 4.4.0 / 4.4.4 ### Python Version 3.12 ### Steps to Reproduce 1. Using the containers from https://github.com/netbox-community/netbox-docker/releases 2. updating container version from 3.4.0 to 3.4.1 3. migrations fail on "extras" / "0133_make_cf_minmax_decimal" ### Expected Behavior migrations apply successfully ### Observed Behavior exception: ``` Operations to perform: Apply all migrations: extras Running migrations: Applying extras.0133_make_cf_minmax_decimal...Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute return self.cursor.execute(sql) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute raise ex.with_traceback(None) psycopg.errors.NumericValueOutOfRange: numeric field overflow DETAIL: A field with precision 16, scale 4 must round to an absolute value less than 10^12. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/netbox/netbox/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 416, in run_from_argv self.execute(*args, **cmd_options) File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 460, in execute output = self.handle(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper res = handle_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 353, in handle post_migrate_state = executor.migrate( ^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 135, in migrate state = self._migrate_all_forwards( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards state = self.apply_migration( ^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 255, in apply_migration state = migration.apply(state, schema_editor) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/migration.py", line 132, in apply operation.database_forwards( File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/operations/fields.py", line 241, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 912, in alter_field self._alter_field( File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 274, in _alter_field super()._alter_field( File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 1165, in _alter_field self.execute( File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 48, in execute return super().execute(sql, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 204, in execute cursor.execute(sql, params) File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute return self._execute_with_wrappers( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers return executor(sql, params, many, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute with self.db.wrap_database_errors: File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute return self.cursor.execute(sql) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute raise ex.with_traceback(None) django.db.utils.DataError: numeric field overflow DETAIL: A field with precision 16, scale 4 must round to an absolute value less than 10^12. ``` ``` $ cat extras/migrations/0133_make_cf_minmax_decimal.py from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('extras', '0132_configcontextprofile'), ] operations = [ migrations.AlterField( model_name='customfield', name='validation_maximum', field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True), ), migrations.AlterField( model_name='customfield', name='validation_minimum', field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True), ), ] ``` to complete the migrations, `max_digits=16` -> was modified to: `max_digits=300` 🙈 . this might not been wise but not sure how else to workaround this issue.
adam added the type: bugpending closurestatus: revisions needednetbox labels 2025-12-29 21:49:38 +01:00
adam closed this issue 2025-12-29 21:49:39 +01:00
Author
Owner

@amsnek commented on GitHub (Oct 23, 2025):

Could this stem "from custom fields" with values larger then 10^12?

@amsnek commented on GitHub (Oct 23, 2025): Could this stem "from custom fields" with values larger then 10^12?
Author
Owner

@arthanson commented on GitHub (Oct 23, 2025):

@amsnek Yes, it looks like you have a custom field with a validation_minimum or validation_maximum set to a value of 999 billion. Can you check your custom fields and there mix/max validation to see if you have an excessively large one.

@arthanson commented on GitHub (Oct 23, 2025): @amsnek Yes, it looks like you have a custom field with a validation_minimum or validation_maximum set to a value of 999 billion. Can you check your custom fields and there mix/max validation to see if you have an excessively large one.
Author
Owner

@amsnek commented on GitHub (Oct 24, 2025):

@arthanson Thanks for your reply!
I double checked and yes, there were two custom ingeger fields integer and the validation set to 999 billion. I have now removed the validation and am thinking about changing those fields to text (if that is possible) and do a regex validation instead.
However, I am not sure if the "workaround" we applied for the migration will have any bad sideeffects (in the future). Is there a way we can re-run the migration again? (it is marked as completed)

@amsnek commented on GitHub (Oct 24, 2025): @arthanson Thanks for your reply! I double checked and yes, there were two custom ingeger fields integer and the validation set to 999 billion. I have now removed the validation and am thinking about changing those fields to text (if that is possible) and do a regex validation instead. However, I am not sure if the "workaround" we applied for the migration will have any bad sideeffects (in the future). Is there a way we can re-run the migration again? (it is marked as completed)
Author
Owner

@github-actions[bot] commented on GitHub (Nov 1, 2025):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Nov 1, 2025): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 8, 2025):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@github-actions[bot] commented on GitHub (Nov 8, 2025): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11767