find . -path "*/migrations/*.py"
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
python manage.py makemigrations
python manage.py migrate
우선적으로 migrations 을 다 지워준다.
그리고 , 만약에 또 안된다면 mysql 데이터를 drop 해준다
하지만 이 방법은 좋은 방법이 아니다 .
You are trying to add a non-nullable field '필드명' to post without a default
이러한 글을 볼수 있다.
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) Quit, and let me add a default in models.py
이 오류는 DB, 모델을 수정할 경우에 자주 발생하는데.
기존에 makemigrations 를 통해 존재하는 정보들을 어떻게 수정할 지 정하지 않았기 때문입니다.
즉, 데이터들이 갈 곳을 잃어 버렸다고 표현을 해야할까요
코드상으로 해결하는 방법과 물리적으로 해결하는 방법이있습니다.
코드
CharField(default = '')
CharField(null = True)
default값과 null 을 허용해서 기존의 데이터들을 null 값이나 default 값으로 설정하는 방법이 있구요
물리
물리적으로는 makemigrations 를 할 때마다 0001_initial.py 와 같은 파일이 생겨납니다.
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()
>>> datetime.date