解决方法:
添加链接描述
https://stackoverflow.com/questions/26185687/you-are-trying-to-add-a-non-nullable-field-new-field-to-userprofile-without-a
models.Model
You are trying to add a non-nullable field ‘aaa’ to post without a default; we can’t do that (the database needs something to populate existing rows).
Please select a fix:
- Provide a one-off default now (will be set on all existing rows with a null value for this column)
- Quit, and let me add a default in models.py
You need to provide a default value:
new_field = models.CharField(max_length=140, default=‘SOME STRING’)
rm your_app/migrations/*
rm db.sqlite3
python manage.py makemigrations
python manage.py migrate
ou can’t add reference to table that have already data inside.
Change:
user = models.OneToOneField(User)
to:
user = models.OneToOneField(User, default = “”)
do:
python manage.py makemigrations
python manage.py migrate
change again:
user = models.OneToOneField(User)
do migration again:
python manage.py makemigrations
python manage.py migrate