我知道从Django 1.7开始,我不需要使用South或任何其他迁移系统,所以我只是使用简单的命令 python manage.py makemigrations
python manage.py makemigrations
但是,我得到的只是这个错误:
You are trying to add a non-nullable field 'new_field' to userprofile without a default; we can't do that (the database needs something to populate existing rows).
这是models.py:
class UserProfile(models.Model): user = models.OneToOneField(User) website = models.URLField(blank=True) new_field = models.CharField(max_length=140)
有哪些选择?
你需要提供一个默认值:
new_field = models.CharField(max_length=140, default='SOME STRING')
如果你处于早期开发周期,并且不关心当前的数据库数据,则可以将其删除然后进行迁移。但是首先,你需要清除迁移目录并从表中删除其行(django_migrations)
rm your_app/migrations/* rm db.sqlite3 python manage.py makemigrations python manage.py migrate