簡體   English   中英

heroku如何運行python manage.py遷移?

[英]How heroku run python manage.py migrate?

我在 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.

確保您已提交遷移文件。 然后運行

heroku run python manage.py migrate

您可以通過以下方式指定應用程序名稱:

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

請參閱此文檔。

你的遷移文件應該提交給你的源代碼控制,並且永遠不要在makemigrations上運行makemigrations

使用提交的遷移文件,這個問題就不存在了。

根據文檔,Heroku 文件系統是只讀的。

這意味着當您與makemigrations斷開連接時,由makemigrations命令創建的文件將被銷毀。

要解決您的問題,您可以:

  1. 將您的遷移文件提交到 Github(或您的源代碼控制系統),然后在 Heroku shell 上運行migrate命令 -推薦
  2. 創建遷移文件,然后在heroku bash shell上運行遷移。 -不推薦用於生產

任何一個

heroku run python manage.py migrate

或者

heroku run python3 manage.py migrate

如果需要指定應用名稱:

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

要使 Heroku 在部署時處理應用遷移,請將以下內容添加到您的 Procfile

release: python manage.py migrate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM