您的位置:首页 > 编程语言 > Go语言

You are trying to add a non-nullable field 'password' to userinfo without a default问题

2017-12-25 17:26 706 查看
当向models.py对应类添加一个新字段

password = models.CharField(max_length=20)

之后,执行python3 manage.py makemigrations命令提示以下信息:
You are trying to add a non-nullable field 'password' to userinfo 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) Quit, and let me add a default in models.py
只需要在字段的后面加一个default=""即可:

password = models.CharField(max_length=20,default="")

再执行 python3 manage.py makemigrations命令:

Migrations for 'grzx':
grzx\migrations\0005_userinfo_password.py
- Add field password to userinfo
再执行python3 manage.py migrate即可向数据库新增字段

Operations to perform:
Apply all migrations: admin, auth, contenttypes, grzx, sessions
Running migrations:
Applying grzx.0005_userinfo_password... OK
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django makemigrations
相关文章推荐