简体   繁体   English

为什么我会收到“CommandError: App 'app_name' 没有迁移。” 什么时候使用 Heroku?

[英]Why do I get “CommandError: App 'app_name' does not have migrations.” when using Heroku?

So I have deployed my Django project to Heroku, and now trying to migrate the database.所以我已经将我的 Django 项目部署到 Heroku,现在正在尝试迁移数据库。 I have everything working fine in my local sever.我在本地服务器上一切正常。 Then I tried to run the commands in heroku, as below.然后我尝试在heroku中运行命令,如下所示。
heroku run python manage.py makemigrations app_name' . heroku run python manage.py makemigrations app_name'
This worked fine.这工作得很好。

Migrations for 'app_name':
  contents\migrations\0001_initial.py
    - Create model Book   
    - Create model Category
    - Create model Content

Then of course, I tried : heroku run python manage.py migrate app_name .然后当然,我试过: heroku run python manage.py migrate app_name
But then I got this error CommandError: App 'app_name' does not have migrations.但是后来我收到了这个错误CommandError: App 'app_name' does not have migrations.

I've done some research for possible issues, none of which were relevant to mine.我对可能的问题做了一些研究,但没有一个与我的相关。
For example I do have __init__.py in the migrations folder inside app_name directory.例如,我在 app_name 目录内的migrations文件夹中有__init__.py Also, I've tried heroku run python manage.py migrate as well as heroku run python manage.py migrate app_name .另外,我试过heroku run python manage.py migrate以及heroku run python manage.py migrate app_name
I'm very confused.我很困惑。 What do you think is the problem?你认为有什么问题? Thanks in advance.提前致谢。 :) :)

我遇到了同样的问题,我不知道为什么,但以下对我有用(一行中有两个命令):

python manage.py makemigrations && python manage.py migrate app_name

As explained in heroku's help article Why are my file uploads missing/deleted?正如heroku 的帮助文章为什么我的文件上传丢失/删除? :

The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Heroku 文件系统是短暂的——这意味着在 dyno 运行时对文件系统的任何更改只会持续到该 dyno 关闭或重新启动。

That is you do generate the migration files but they cease to exist shortly after when the app is reloaded.也就是说,您确实生成了迁移文件,但在重新加载应用程序后不久它们就不再存在。

In general the strategy you take is not a good approach to migrations as this can cause various issues, let's say you have multiple production servers each generates their own migrations this causes a conflict!一般来说,您采取的策略不是迁移的好方法,因为这可能会导致各种问题,假设您有多个生产服务器,每个服务器都生成自己的迁移,这会导致冲突! In your situation suppose you do migrate this way and then later you want to add some new models this again will cause you problems.在您的情况下,假设您确实以这种方式迁移,然后您想添加一些新模型,这再次会给您带来问题。

One should always add their migrations to the version control (git, etc.) commit them and push them to production (here your heroku dyno).应该始终将他们的迁移添加到版本控制(git 等)提交它们并将它们推送到生产(这里是你的 heroku dyno)。 That is run python manage.py makemigrations locally , commit the generated migrations, push them and then run heroku run python manage.py migrate .在本地运行python manage.py makemigrations ,提交生成的迁移,推送它们,然后运行heroku run python manage.py migrate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM