---
title: "[メモ]docker環境でnetbox v4.0.xからv4.1以降への更新が失敗する場合の対処法"
id: "7218"
type: "post"
slug: "%e3%83%a1%e3%83%a2docker%e7%92%b0%e5%a2%83%e3%81%a7netbox-v4-0-x%e3%81%8b%e3%82%89v4-1%e4%bb%a5%e9%99%8d%e3%81%b8%e3%81%ae%e6%9b%b4%e6%96%b0%e3%81%8c%e5%a4%b1%e6%95%97%e3%81%99%e3%82%8b%e5%a0%b4"
published_at: "2025-05-26T12:48:33+00:00"
modified_at: "2025-05-26T23:45:21+00:00"
url: "https://www.okin-jp.net/archives/7218"
markdown_url: "https://www.okin-jp.net/archives/7218.md"
excerpt: "MacのWindowsAppからxrdpにrdp接続するとusキーボードになってしまうので調査 Continue reading"
taxonomy_category:
  - "Linux"
  - "Server"
taxonomy_post_tag:
  - "Netbox"
  - "network"
  - "サーバー運用"
  - "ネットワーク"
  - "運用メモ"
---

## 概要

v4.0.xからv4.1.x以降(v4.2.x、v4.3.x含む)へのマイグレーションに失敗する。

Shell

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 | 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 416, 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 460, 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 353, 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 255, 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 196, 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 9, in update_content_types netbox-1 | ContentType.objects.using(db_alias).filter(app_label='core', model='objectchange').delete() netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1196, 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 343, 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 398, in __bool__ netbox-1 | self._fetch_all() netbox-1 | File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1945, 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 1623, 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 |

| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | netbox-1 \| ⚙️ Applying database migrationsnetbox-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, wirelessnetbox-1 \| Running migrations:netbox-1 \| Traceback (most recent call last):netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _executenetbox-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 executenetbox-1 \| raise ex.with_traceback(None)netbox-1 \| psycopg.errors.UndefinedTable: relation "extras_objectchange" does not existnetbox-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_linenetbox-1 \| utility.execute()netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in executenetbox-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 416, in run_from_argvnetbox-1 \| self.execute(*args, **cmd_options)netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/core/management/base.py", line 460, in executenetbox-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 wrappernetbox-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 353, in handlenetbox-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 migratenetbox-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_forwardsnetbox-1 \| state = self.apply_migration(netbox-1 \| ^^^^^^^^^^^^^^^^^^^^^netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 255, in apply_migrationnetbox-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 applynetbox-1 \| operation.database_forwards(netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/migrations/operations/special.py", line 196, in database_forwardsnetbox-1 \| self.code(from_state.apps, schema_editor)netbox-1 \| File "/opt/netbox/netbox/extras/migrations/0117_move_objectchange.py", line 9, in update_content_typesnetbox-1 \| ContentType.objects.using(db_alias).filter(app_label='core', model='objectchange').delete()netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1196, in deletenetbox-1 \| collector.collect(del_query)netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/deletion.py", line 343, in collectnetbox-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 398, in __bool__netbox-1 \| self._fetch_all()netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1945, in _fetch_allnetbox-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 1623, in execute_sqlnetbox-1 \| cursor.execute(sql, params)netbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in executenetbox-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_wrappersnetbox-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 _executenetbox-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_valuenetbox-1 \| File "/opt/netbox/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 105, in _executenetbox-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 executenetbox-1 \| raise ex.with_traceback(None)netbox-1 \| django.db.utils.ProgrammingError: relation "extras_objectchange" does not existnetbox-1 \| LINE 1: ...ct_type_id", "extras_objectchange"."user_id" FROM "extras_ob...netbox-1 \| |
| --- | --- |

## 解決策

Shell

# netboxのcompose.ymlがあるディレクトリに移動 cd /opt/netbox # netbox関連を全部止める docker compose down # (Valkeyへの切り換えに関連して)redisのボリュームを2つ消す docker volume list | grep redis docker volume rm xxxx_netbox-redis-cache-data xxxx_netbox-redis-data # postgresだけ起動 docker compose up postgres -d # postgresがエラーを吐いてないか確認(エラーがあれば対処する) docker compose ps docker compose logs postgres # postgresのpsqlを実行 docker compose exec postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB' # マイグレーションの削除と権限の割り当て DELETE from django_migrations WHERE name='0011_move_objectchange'; GRANT ALL ON SCHEMA public TO netbox; # psqlから抜ける \q # フォアグランドで実行してマイグレーションが完了することを確認する docker compose up

| 123456789101112131415161718192021 | # netboxのcompose.ymlがあるディレクトリに移動cd /opt/netbox# netbox関連を全部止めるdocker compose down# (Valkeyへの切り換えに関連して)redisのボリュームを2つ消すdocker volume list \| grep redisdocker volume rm xxxx_netbox-redis-cache-data xxxx_netbox-redis-data# postgresだけ起動docker compose up postgres -d# postgresがエラーを吐いてないか確認(エラーがあれば対処する)docker compose psdocker compose logs postgres# postgresのpsqlを実行docker compose exec postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'# マイグレーションの削除と権限の割り当てDELETE from django_migrations WHERE name='0011_move_objectchange';GRANT ALL ON SCHEMA public TO netbox;# psqlから抜ける\q# フォアグランドで実行してマイグレーションが完了することを確認するdocker compose up |
| --- | --- |

[https://github.com/netbox-community/netbox/issues/17401#issuecomment-2344450383](https://github.com/netbox-community/netbox/issues/17401#issuecomment-2344450383)

### メモ

弊運用環境ではredisからvalkeyへの切り換えによるrdb読み込みエラー、postgresのバージョンアップ、netboxのマイグレーション失敗が複合していたので非常に厄介だったが当該issueを見つけた時点で前者2つの問題は解決済みだったため、実際はマイグレーションの削除と権限のsqlだけ実行した。

![おきん(blog)](https://secure.gravatar.com/avatar/90fa8845304183a491e9f3bfa0a6a44e46e25882407e4aa652815d725d55bd8c?s=100&r=g)

[おきん(blog)](https://www.okin-jp.net/archives/author/oops-okin)

[https://mi.okin-jp.net/@okin_p](https://mi.okin-jp.net/@okin_p)
(Misskey)  
 [https://fi.okin-jp.net/@okin_p](https://fi.okin-jp.net/@okin_p)
(Firefish)  
 [https://si.okin-jp.net/@okin_p](https://si.okin-jp.net/@okin_p)
(Mastodon)

[https://fedifile.net/@okin_p/profile/](https://fedifile.net/@okin_p/profile/)
  
 [https://twpf.jp/okin_p](https://twpf.jp/okin_p)
  
 [http://profile.hatena.ne.jp/okin_p/](http://profile.hatena.ne.jp/okin_p/)

名前：おきん  
 やってること：面倒なことをPHPにやらせる、IPv6でなにかする、車で移動する  
 主なガジェット：Google Pixel 4a (5G) ,iPhone XS(ジャンク), iPad mini5, その他

種別：IPv6 Single stack 猫

パソコンやガジェットについて書いていく…予定。

[https://twitter.com/okin_p](https://twitter.com/okin_p)
[https://si.okin-jp.net/@okin_p](https://si.okin-jp.net/@okin_p)

### *関連記事*

### コメントを残す[コメントをキャンセル](/archives/7218#respond)

このサイトはスパムを低減するために Akismet を使っています。[コメントデータの処理方法の詳細はこちらをご覧ください](https://akismet.com/privacy/)
。
