在Django中使用RD向弹性Beanstalk上的现有模型添加新字段时出错

2024-04-19 06:44:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试向Django中的现有模型添加新字段时遇到了一个错误。它使用MySQL RDS数据库托管在弹性beanstalk上。在

当我试图访问包含新字段的模型时,出现以下错误:

(1054,“未知列”存在_model.new_字段'在'字段列表')

有没有更好的方法来处理EB上的Django移民?这是我的.config文件:

container_commands:
  01_makemigrations:
    command: "source /opt/python/run/venv/bin/activate && python manage.py makemigrations --noinput"
    leader_only: true
  02_migrate:
    command: "source /opt/python/run/venv/bin/activate && python manage.py migrate --noinput"
    leader_only: true
  03_createsu:
    command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
    leader_only: true
  04_collectstatic:
    command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"

有什么帮助吗?谢谢!在


Tags: djangorunpy模型truesourceonlybin
1条回答
网友
1楼 · 发布于 2024-04-19 06:44:33

原来我必须在eb deploy之前在本地运行python manage.py makemigrations。这样,就创建了迁移文件,当在eb实例上运行migrate时,它知道如何相应地更改数据库。在

我的.config文件现在是:

container_commands:
  01_migrate:
    command: "source /opt/python/run/venv/bin/activate && python manage.py migrate  noinput"
    leader_only: true
  02_createsu:
    command: "source /opt/python/run/venv/bin/activate && python manage.py createsu"
    leader_only: true
  03_collectstatic:
    command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic  noinput"

相关问题 更多 >