提问人:ENV 提问时间:11/17/2023 更新时间:11/17/2023 访问量:26
如何使用 docker 运行 makemigrations
How to run makemigrations with docker
问:
我有一个 Django 项目在带有诗歌的 docker 容器中运行。我想更改其中一个现有模型以添加一个额外的 JSON 字段。当我在本地运行项目并尝试使用
python manage.py makemigrations
python manage.py migrate
虽然 makemigrations 运行良好,但 migrate 运行不正常。当我尝试迁移时,出现以下错误:
Traceback (most recent call last):
File "/Users/ENV/Desktop/inventory/manage.py", line 24, in <module>
main()
File "/Users/ENV/Desktop/inventory/manage.py", line 16, in main
execute_from_command_line(sys.argv)
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/ENV/Desktop/inventory/.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 "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/core/management/base.py", line 106, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 117, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/backends/base/base.py", line 330, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File "/Users/ENV/Desktop/inventory/.venv/lib/python3.12/site-packages/django/db/backends/dummy/base.py", line 20, in complain
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
当我在本地运行数据库时,数据库已正确配置。配置都在 docker 容器中,该容器以诗歌的形式运行。所以我想知道是否因为我使用 docker 运行它,所以有一种不同的方法可以用我不知道的那些迁移来更新数据库。
任何这方面的帮助将不胜感激!
答: 暂无答案
评论