heroku如何运行pythonmanage.py迁移?

yiytaume  于 2023-01-21  发布在  Python
关注(0)|答案(5)|浏览(81)

我在Heroku中部署了一个简单的Django应用程序
步骤:

- git push heroku master

- heroku run python manage.py makemigrations ( or + app_name)

它似乎影响到:

0002_main.py:
- Create model Comment
- Remove field status from match
- Remove field quantity from slot
- Add field avatar to account
- Add field slots to match
- Alter field verification_code on account
- Alter field verification_code on slot
- Add field match_object to comment
- Add field user to comment
- Alter index_together for comment (1 constraint(s))

然后我跑了

- heroku run python manage.py migrate

但是我收到了:

Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
qcuzuvrc

qcuzuvrc1#

请确保已提交迁移文件。然后运行

heroku run python manage.py migrate

您可以通过以下方式指定应用程序名称:

heroku run python manage.py migrate -a <app-name>

请参阅本文档。

2uluyalo

2uluyalo2#

您的迁移文件应该提交到源代码管理,并且永远不要在heroku上运行makemigrations
使用提交的迁移文件,此问题将不复存在。

6yt4nkrj

6yt4nkrj3#

根据文档,Heroku文件系统是只读的。
这意味着当您断开与dyno的连接时,由makemigrations命令创建的文件将被销毁。
要解决您的问题,您可以:
1.将迁移文件提交到Github(或源代码控制系统),然后在Heroku shell上运行migrate命令- * 推荐使用 *
1.创建迁移文件,然后在heroku bash shell上运行迁移。- * 不建议用于生产环境 *

vvppvyoh

vvppvyoh4#

或者
heroku run python manage.py migrate

heroku run python3 manage.py migrate
如果需要指定应用程序名称:
heroku run python3 manage.py migrate -a <app-name>

fnx2tebb

fnx2tebb5#

要让Heroku在部署时处理迁移应用,请将以下内容添加到Procfile
release: python manage.py migrate

相关问题