on
Django Heroku Database Migrate Error
Django Heroku Database Migrate Error
Your models in app(s): 'app1', 'app2', 'app3' 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.
Error :
헤로쿠 서버에 DB를 등록하는 과정에서
다음 에러가 발생하는 경우가 존재한다.
헤로쿠에 python manage.py migrate를
계속 진행하는데, 서버 DB에 migrate가
정상적으로 되지 않는다면,
다음을 참고해서 fix 하길 바란다.
이 에러가 발생하는 이유는
로컬에서 migrations 한 DB가
헤로쿠 서버에 정상적으로
migration이 안됬기 때문이다.
로컬에서 migration을 다시 진행하고,
정상적으로 DB생성이 완료 된 후에
헤로쿠 서버에 migration을 다시
진행해준다.
Django 같은 경우
ORM으로 DB를 관리하기 때문에,
SQL로 DB를 설계 해주지 않아도 되지만,
DB migration 작업은 신경써서
서버 + 로컬 둘다 해줘야 한다.
Solution :
1. (add/modify some someapp/models.py) : models.py를 수정한다.
2. python manage.py makemigrations someapp : 로컬에서 migrations을 진행
3. python manage.py migrate : 로컬에서 migrate(모델 DB로 반영) 진행
4. git add someapp/migrations/*.py (to add the new migration file) : 변경사항을 git에 add
5. git commit -m "added migration for app someapp" : 변경사항을 git에 commit
6. git push heroku : 변경사항을 git에 push
7. heroku run python manage.py migrate : 헤로쿠에 migrate 재진행
반드시 로컬에서 migrate를 모두 진행하고,
git에 변경사항을 push 하고 난 뒤에
heroku 서버에 migrate를 해줘야
DB 변경사항이 서버에 정상적으로
반영된다.
from http://incomeplus.tistory.com/179 by ccl(A) rewrite - 2021-10-08 13:26:47