Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database migration fails when updating from 2.9.1 to 3.0.2 #1341

Open
nakal opened this issue Oct 25, 2024 · 0 comments
Open

Database migration fails when updating from 2.9.1 to 3.0.2 #1341

nakal opened this issue Oct 25, 2024 · 0 comments

Comments

@nakal
Copy link

nakal commented Oct 25, 2024

Current Behavior

I tried to update the repository from 2.9.1 to 3.0.2.

When starting the netbox container the migration fails. See log.

PostgreSQL and Valkey (redis/redis-cache container) are up and running.

Expected Behavior

The migration finishes successfully and Netbox starts using the new version.

Docker Compose Version

docker-compose version 1.29.2, build unknown

Docker Version

Docker version 20.10.24+dfsg1, build 297e128

The git Revision

git version 2.39.5

The git Status

nothing to commit, working tree clean

Startup Command

docker-compose up

NetBox Logs

Starting netbox-docker_netbox_1 ... done                                        
Attaching to netbox-docker_netbox_1                                             
netbox_1               | ⚙ Applying database migrations                         
netbox_1               | 🧬 loaded config '/etc/netbox/config/configuration.py' 
netbox_1               | 🧬 loaded config '/etc/netbox/config/extra.py'         
netbox_1               | 🧬 loaded config '/etc/netbox/config/logging.py'       
netbox_1               | 🧬 loaded config '/etc/netbox/config/plugins.py'       
netbox_1               | Operations to perform:                                 
netbox_1               |   Apply all migrations: account, auth, circuits, contenttypes, core, dcim, django_rq, extras, ipam, sessions, social_django, taggit, tenancy, users, virtualization, vpn, wireless
netbox_1               | Running migrations:                                                             
netbox_1               |   Applying extras.0117_move_objectchange...Traceback (most recent call last):                                                                                                     
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _execute                                                                         
netbox_1               |     return self.cursor.execute(sql, params)                                                              
netbox_1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                               
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute                                                                                     
netbox_1               |     raise ex.with_traceback(None)                                                                        
netbox_1               | psycopg.errors.UndefinedTable: relation "extras_objectchange" does not exist                   
netbox_1               | LINE 1: ...ct_type_id", "extras_objectchange"."user_id" FROM "extras_ob...                               
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.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line                                                 
netbox_1               |     utility.execute()                                                                                                             
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute                                                                   
netbox_1               |     self.fetch_command(subcommand).run_from_argv(self.argv)                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
netbox_1               |     self.execute(*args, **cmd_options)                                                                                            
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute      
netbox_1               |     output = self.handle(*args, **options)                                                                    
netbox_1               |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper                                                                       
netbox_1               |     res = handle_func(*args, **kwargs)                                                                     
netbox_1               |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                           
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 356, in handle                                                            
netbox_1               |     post_migrate_state = executor.migrate(                                                                                        
netbox_1               |                          ^^^^^^^^^^^^^^^^^                                                                             
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 135, in migrate                                                                     
netbox_1               |     state = self._migrate_all_forwards(                                                                       
netbox_1               |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards                                                       
netbox_1               |     state = self.apply_migration(                                                                                                 
netbox_1               |             ^^^^^^^^^^^^^^^^^^^^^                                                                                           
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
netbox_1               |     state = migration.apply(state, schema_editor)                                                                                 
netbox_1               |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                           
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/migration.py", line 132, in apply           
netbox_1               |     operation.database_forwards(                                                                                     
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards                                                 
netbox_1               |     self.code(from_state.apps, schema_editor)                                                                                     
netbox_1               |   File "/opt/netbox/netbox/extras/migrations/0117_move_objectchange.py", line 8, in update_content_types                        
netbox_1               |     ContentType.objects.filter(app_label='core', model='objectchange').delete()                                           
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1187, in delete               
netbox_1               |     collector.collect(del_query)                                                                                   
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/deletion.py", line 348, in collect  
netbox_1               |     if getattr(on_delete, "lazy_sub_objs", False) or sub_objs:                                                
netbox_1               |                                                      ^^^^^^^^                                            
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 414, in __bool__    
netbox_1               |     self._fetch_all()                                                                                         
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1928, in _fetch_all                                                                        
netbox_1               |     self._result_cache = list(self._iterable_class(self))                                                        
netbox_1               |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                             
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 91, in __iter__                                                                                               
netbox_1               |     results = compiler.execute_sql(                                                   
netbox_1               |               ^^^^^^^^^^^^^^^^^^^^^                                                   
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1562, in execute_sql                                                                                   
netbox_1               |     cursor.execute(sql, params)                                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute                                                                                              
netbox_1               |     return self._execute_with_wrappers(                                               
netbox_1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                               
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers                                                                               
netbox_1               |     return executor(sql, params, many, context)                                       
netbox_1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute                                                                                            
netbox_1               |     with self.db.wrap_database_errors:                                                
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/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.12/site-packages/django/db/backends/utils.py", line 105, in _execute                                                                                            
netbox_1               |     return self.cursor.execute(sql, params)                                           
netbox_1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                           
netbox_1               |   File "/opt/netbox/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute                                                                                                        
netbox_1               |     raise ex.with_traceback(None)                                                     
netbox_1               | django.db.utils.ProgrammingError: relation "extras_objectchange" does not exist       
netbox_1               | LINE 1: ...ct_type_id", "extras_objectchange"."user_id" FROM "extras_ob...            
netbox_1               |                                                              ^                        
netbox-docker_netbox_1 exited with code 1

Content of docker-compose.override.yml

version: '3.4'
services:
  netbox:
    ports:
      - 8045:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant