我知道从Django 1.7,我不需要使用南方或任何其他迁移系统,所以我只是使用简单的命令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)有什么选择?
发布于 2019-09-17 02:57:53
不能添加对表中已经有数据的引用。
更改:
user = models.OneToOneField(User)至:
user = models.OneToOneField(User, default = "")做:
python manage.py makemigrations
python manage.py migrate再次改变:
user = models.OneToOneField(User)再次移徙:
python manage.py makemigrations
python manage.py migratehttps://stackoverflow.com/questions/26185687
复制相似问题