Django | Migrate Error

김민호·2021년 9월 30일
0

DJANGO

목록 보기
8/18

$ python manage.py makemigrations

You are trying to change the nullable field 'other_info' on user to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Ignore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)
 3) Quit, and let me add a default in models.py
Select an option:

app의 models.py를 수정하고 마이그레이션을 하려고 하는데 이런 에러 발생

일단 어제 겁도없이 2를 눌렀다가 구글링해도 나오지 않는 에러가 뜨고 하루 동안 아무 행동도 할 수 없는 지경까지 이르렀다

You are trying to change the nullable field 'other_info' on user to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
내가 지금 null값이 올 수 있는 'other_info'라는 필드를 디폴트값을 주지 않고 null값을 허용하지 않는 필드로 바꾸려고 하고 있고 그렇게는 불가능하다는 것 같다

기존에 migrations와 migrate를 통해 입력했던 데이터들이 새로운 migrations로 인해 뭔가 충돌을 하는 것 같다.

기존의 null값이 허용되어 있던 필드 중 비어있던 필드가 null값을 허용하지 않는 걸로 바뀌니까 빈 곳을 어떻게 처리해야 할지 모르겠다는건가....?

암튼 해당하는 테이블의 데이터를 전부 삭제하고 다시 넣어봤는데도 안됐는데 동기분의 도움과 여기를 참고해서 해결했다

해결방법

3) Quit, and let me add a default in models.py 를 선택하고
해당 필드에 속성값으로 null=True 이나 default='' 를 주니까 해결됐다

profile
개발자로서의 삶은 https://velog.io/@maxminos 에서 기록하고 있습니다 😀

0개의 댓글