Upgrade 3.3.9 to 3.4.1 DB migrations failing #7437

Closed
opened 2025-12-29 20:23:29 +01:00 by adam · 3 comments
Owner

Originally created by @baccenfutter on GitHub (Jan 2, 2023).

NetBox version

v3.4.1

Python version

3.10

Steps to Reproduce

  • bump version string in docker-compose.yml from 3.3.9 to 3.4.1
  • run docker-compose pull
  • run docker-compose up -d

Expected Behavior

bootstrap, migrate, done.

Observed Behavior

netbox_1               | Operations to perform:                                                                                                                                                                     
netbox_1               |   Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless                                                                                                                                 
netbox_1               | Running migrations:                                                                                                                                                                                                                                     
netbox_1               | Traceback (most recent call last):                                                                                                                                                         
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute                                                                                                                                                
netbox_1               |     return self.cursor.execute(sql)                                                                                                                                                        
netbox_1               | psycopg2.errors.UniqueViolation: could not create unique index "dcim_device_unique_name_site"                                                                                                                                                           
netbox_1               | DETAIL:  Key (lower(name::text), site_id)=(gsmk, 1) is duplicated.                                                                                                                         
netbox_1               |                                                                                                                                                                                                                                                         
netbox_1               |                                                                                                                                                                                            
netbox_1               | The above exception was the direct cause of the following exception:                                                                                                                                                                                    
netbox_1               |                                                                                                                                                                                            
netbox_1               | Traceback (most recent call last):                                                                                                                                                                                                                      
netbox_1               |   File "/opt/netbox/netbox/./manage.py", line 10, in <module>                                                                                                                              
netbox_1               |     execute_from_command_line(sys.argv)                                                                                                                                                                                                                 
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line                                                          
netbox_1               |     utility.execute()                                                                                                                                                                                                                                   
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute                                                                            
netbox_1               |     self.fetch_command(subcommand).run_from_argv(self.argv)                                                                                                                                                                                             
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv                                                                          
netbox_1               |     self.execute(*args, **cmd_options)                                                                                                                                                                                                                  
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute                                                                                
netbox_1               |     output = self.handle(*args, **options)                                                                                                                                                                                                              
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped                                                                                 
netbox_1               |     res = handle_func(*args, **kwargs)                                                                                                                                                                                                                  
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 349, in handle                                                                     
netbox_1               |     post_migrate_state = executor.migrate(                                                                                                                                                                                                              
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate                                                                              
netbox_1               |     state = self._migrate_all_forwards(                                                                                                                                                                                                                 
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards                                                                
netbox_1               |     state = self.apply_migration(                                                                                                                                                                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration                                                                      
netbox_1               |     state = migration.apply(state, schema_editor)                                                                                                                                                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 130, in apply                                                                               
netbox_1               |     operation.database_forwards(                                                 
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/operations/models.py", line 1040, in database_forwards                                                          
netbox_1               |     schema_editor.add_constraint(model, self.constraint)                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 515, in add_constraint                                                                                                                                                                                 
netbox_1               |     self.execute(sql, params=None)                                                                             
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 199, in execute                                                                                                                                                                                        
netbox_1               |     cursor.execute(sql, params)                                                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute                                                                                                                                                 
netbox_1               |     return self._execute_with_wrappers(                                                                                               
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers                                                                                                                                                                                
netbox_1               |     return executor(sql, params, many, context)                                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute                                                                                                                                                                                              
netbox_1               |     with self.db.wrap_database_errors:                                                                                                
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__                                                                                                                                                                                                       
netbox_1               |     raise dj_exc_value.with_traceback(traceback) from exc_value                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute                                                                                                                                                                                              
netbox_1               |     return self.cursor.execute(sql)                                                                                                   
netbox_1               | django.db.utils.IntegrityError: could not create unique index "dcim_device_unique_name_site"                                                                                                                                                                                                          
netbox_1               | DETAIL:  Key (lower(name::text), site_id)=(gsmk, 1) is duplicated.                                                                    
Originally created by @baccenfutter on GitHub (Jan 2, 2023). ### NetBox version v3.4.1 ### Python version 3.10 ### Steps to Reproduce - bump version string in docker-compose.yml from 3.3.9 to 3.4.1 - run `docker-compose pull` - run `docker-compose up -d` ### Expected Behavior bootstrap, migrate, done. ### Observed Behavior ``` netbox_1 | Operations to perform: netbox_1 | Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless netbox_1 | Running migrations: netbox_1 | Traceback (most recent call last): netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute netbox_1 | return self.cursor.execute(sql) netbox_1 | psycopg2.errors.UniqueViolation: could not create unique index "dcim_device_unique_name_site" netbox_1 | DETAIL: Key (lower(name::text), site_id)=(gsmk, 1) is duplicated. netbox_1 | netbox_1 | netbox_1 | The above exception was the direct cause of the following exception: netbox_1 | netbox_1 | Traceback (most recent call last): netbox_1 | File "/opt/netbox/netbox/./manage.py", line 10, in <module> netbox_1 | execute_from_command_line(sys.argv) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line netbox_1 | utility.execute() netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute netbox_1 | self.fetch_command(subcommand).run_from_argv(self.argv) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv netbox_1 | self.execute(*args, **cmd_options) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute netbox_1 | output = self.handle(*args, **options) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped netbox_1 | res = handle_func(*args, **kwargs) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 349, in handle netbox_1 | post_migrate_state = executor.migrate( netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 135, in migrate netbox_1 | state = self._migrate_all_forwards( netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards netbox_1 | state = self.apply_migration( netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 252, in apply_migration netbox_1 | state = migration.apply(state, schema_editor) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/migration.py", line 130, in apply netbox_1 | operation.database_forwards( netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/migrations/operations/models.py", line 1040, in database_forwards netbox_1 | schema_editor.add_constraint(model, self.constraint) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 515, in add_constraint netbox_1 | self.execute(sql, params=None) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/base/schema.py", line 199, in execute netbox_1 | cursor.execute(sql, params) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute netbox_1 | return self._execute_with_wrappers( netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers netbox_1 | return executor(sql, params, many, context) netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute netbox_1 | with self.db.wrap_database_errors: netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__ netbox_1 | raise dj_exc_value.with_traceback(traceback) from exc_value netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute netbox_1 | return self.cursor.execute(sql) netbox_1 | django.db.utils.IntegrityError: could not create unique index "dcim_device_unique_name_site" netbox_1 | DETAIL: Key (lower(name::text), site_id)=(gsmk, 1) is duplicated. ```
adam added the type: bug label 2025-12-29 20:23:29 +01:00
adam closed this issue 2025-12-29 20:23:29 +01:00
Author
Owner

@baccenfutter commented on GitHub (Jan 2, 2023):

Excerpt from django_migrations:

 482 | circuits          | 0039_unique_constraints                                 | 2023-01-02 07:18:33.39728+00
 483 | circuits          | 0040_provider_remove_deprecated_fields                  | 2023-01-02 07:18:33.902761+00
 484 | circuits          | 0041_standardize_description_comments                   | 2023-01-02 07:18:33.96943+00
 485 | tenancy           | 0008_unique_constraints                                 | 2023-01-02 07:18:34.543866+00
 486 | tenancy           | 0009_standardize_description_comments                   | 2023-01-02 07:18:34.610199+00
 487 | ipam              | 0061_fhrpgroup_name                                     | 2023-01-02 07:18:34.676015+00
 488 | ipam              | 0062_unique_constraints                                 | 2023-01-02 07:18:35.253982+00
 489 | ipam              | 0063_standardize_description_comments                   | 2023-01-02 07:18:36.458948+00
 490 | extras            | 0078_unique_constraints                                 | 2023-01-02 07:18:36.571293+00
 491 | extras            | 0079_scheduled_jobs                                     | 2023-01-02 07:18:36.672958+00
 492 | extras            | 0080_customlink_content_types                           | 2023-01-02 07:18:36.993055+00
 493 | extras            | 0081_exporttemplate_content_types                       | 2023-01-02 07:18:37.612183+00
 494 | extras            | 0082_savedfilter                                        | 2023-01-02 07:18:37.761069+00
@baccenfutter commented on GitHub (Jan 2, 2023): Excerpt from `django_migrations`: ``` 482 | circuits | 0039_unique_constraints | 2023-01-02 07:18:33.39728+00 483 | circuits | 0040_provider_remove_deprecated_fields | 2023-01-02 07:18:33.902761+00 484 | circuits | 0041_standardize_description_comments | 2023-01-02 07:18:33.96943+00 485 | tenancy | 0008_unique_constraints | 2023-01-02 07:18:34.543866+00 486 | tenancy | 0009_standardize_description_comments | 2023-01-02 07:18:34.610199+00 487 | ipam | 0061_fhrpgroup_name | 2023-01-02 07:18:34.676015+00 488 | ipam | 0062_unique_constraints | 2023-01-02 07:18:35.253982+00 489 | ipam | 0063_standardize_description_comments | 2023-01-02 07:18:36.458948+00 490 | extras | 0078_unique_constraints | 2023-01-02 07:18:36.571293+00 491 | extras | 0079_scheduled_jobs | 2023-01-02 07:18:36.672958+00 492 | extras | 0080_customlink_content_types | 2023-01-02 07:18:36.993055+00 493 | extras | 0081_exporttemplate_content_types | 2023-01-02 07:18:37.612183+00 494 | extras | 0082_savedfilter | 2023-01-02 07:18:37.761069+00 ```
Author
Owner

@TrixaFett commented on GitHub (Jan 2, 2023):

I have the same issue. I cannot ever docker-compose up after, then it says that my docker container is unhealthy.

ERROR: for netbox-housekeeping Container "xxxxxxxxxxxx" is unhealthy.

ERROR: for netbox-worker Container "xxxxxxxxxxxx" is unhealthy.
ERROR: Encountered errors while bringing up the project.

@TrixaFett commented on GitHub (Jan 2, 2023): I have the same issue. I cannot ever docker-compose up after, then it says that my docker container is unhealthy. ERROR: for netbox-housekeeping Container "xxxxxxxxxxxx" is unhealthy. ERROR: for netbox-worker Container "xxxxxxxxxxxx" is unhealthy. ERROR: Encountered errors while bringing up the project.
Author
Owner

@PaulR282 commented on GitHub (Jan 2, 2023):

netbox_1               | Operations to perform:                                                                                                                                                                     
netbox_1               |   Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless                                                                                                                                 
netbox_1               | Running migrations:                                                                                                                                                                                                                                     
netbox_1               | Traceback (most recent call last):                                                                                                                                                         
netbox_1               |   File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute                                                                                                                                                
netbox_1               |     return self.cursor.execute(sql)                                                                                                                                                        
netbox_1               | psycopg2.errors.UniqueViolation: could not create unique index "dcim_device_unique_name_site"                                                                                                                                                           
netbox_1               | DETAIL:  Key (lower(name::text), site_id)=(gsmk, 1) is duplicated.                                                                                                                         

Looks like you have a duplicate name, which is now a problem since #9249. Have a look at your site gsmk. I'm not sure if the site itself is duplicated or a device within the site, but it's probably a device.

@PaulR282 commented on GitHub (Jan 2, 2023): > ``` > netbox_1 | Operations to perform: > netbox_1 | Apply all migrations: admin, auth, circuits, contenttypes, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, wireless > netbox_1 | Running migrations: > netbox_1 | Traceback (most recent call last): > netbox_1 | File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 87, in _execute > netbox_1 | return self.cursor.execute(sql) > netbox_1 | psycopg2.errors.UniqueViolation: could not create unique index "dcim_device_unique_name_site" > netbox_1 | DETAIL: Key (lower(name::text), site_id)=(gsmk, 1) is duplicated. > ``` Looks like you have a duplicate name, which is now a problem since #9249. Have a look at your site `gsmk`. I'm not sure if the site itself is duplicated or a device within the site, but it's probably a device.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7437