简体   繁体   中英

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. I have everything working fine in my local sever. Then I tried to run the commands in heroku, as below.
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 .
But then I got this error 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. Also, I've tried heroku run python manage.py migrate as well as 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? :

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.

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). That is run python manage.py makemigrations locally , commit the generated migrations, push them and then run heroku run python manage.py migrate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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