2016-11-24 129 views
0

我在Heroku上部署了一個簡單的Django應用程序heroku如何運行python manage.py遷移?

步驟:

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

回答

2

您的遷移文件應該提交給您的源代碼管理,並且絕不會在heroku上運行makemigrations

對於已提交的遷移文件,此問題變得不存在。

+1

沒錯,我錯過了遷移文件,我只是在heroku上運行makemigrations –

1

根據documentation,Heroku文件系統是隻讀的。

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

爲了解決您的問題,您可以:

  1. 提交您的遷移文件到Github上(或你的源代碼控制系統),然後在Heroku的外殼運行migrate命令 - 建議
  2. 創建遷移文件,然後在heroku bash shell上運行遷移。 - 不建議在生產上
3

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

heroku run python manage.py migrate 

請參閱此文檔。