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
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在models.py新增表字段出现You are trying to add a non-nullable field 'message' to usermessage without a
- Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
- Django model :add a non-nullable field 'SKU' to product without a default; we can't do that
- docker 解决:Get http:///var/run/docker.sock/v1.19/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
- Docker Are you trying to connect to a TLS-enabled daemon without TLS?
- 修改ListItem时出现Error: Invalid data has been used to update the list item. The field you are trying to update may be read only.
- Tutorial: Extend UniShare - Add /me API(for getting userinfo) to Facebook instance
- Are you trying to connect to a TLS-enabled daemon without TLS?
- FATA[0000] (省略) Are you trying to connect to a TLS-enabled daemon without TLS?
- Windows环境下安装beautifulsoup4出现 'You are trying to run the Python 2 version of Beautiful Soup ....错误
- ErrorCode:1175.You are using safe update mode and you tried to update a table without a WHERE that u
- mysql Error Code: 1175 You are using safe update mode and you tried to update a table without a W
- Caused by: Unable to locate parent package [json-default] for [class com.you.user.action.StudentActi
- 在Ubuntu中遇到Unable to lock the administration directory (-var-lib-dpkg-),are you root- 问题解决办法
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- VS.NET 2003 Error - The project you are trying to open is a Web project. You need to open it by specifying its URL path.
- 处理MySQL更新表时ErrorCode:1175.You are using safe update mode and you tried to update a table without a WHERE that uses a KEY
- After logging in to the Lotus Notes Client, you are prompted for a password in DOS-like window (Viru
- Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE tha
- Jenkins部署:The username and password you provided are not correct (error 401)