Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
2017-04-21 20:15
746 查看
name = models.CharField(max_length=50)
执行:python manage.py makemirations出现以下错误:
You are trying to add a non-nullable field 'name' to contact 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
Select an option:
解决方法:
先给'name'任意初始值:name = models.CharField(max_length=50, default='abc')
然后执行:python manage.py makemirations
再执行:python manage.py migrate
再将default删去,即执行:name = models.CharField(max_length=50)
执行:python manage.py makemirations
再执行:python manage.py migrate
解决!
注意:在开发过程中,数据库同步误操作之后,难免会遇到后面不能同步成功的情况,解决这个问题的一个简单粗暴方法是把migrations目录下的脚本(除__init__.py之外)全部删掉,再把数据库删掉之后创建一个新的数据库,数据库同步操作再重新做一遍。
执行:python manage.py makemirations出现以下错误:
You are trying to add a non-nullable field 'name' to contact 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
Select an option:
解决方法:
先给'name'任意初始值:name = models.CharField(max_length=50, default='abc')
然后执行:python manage.py makemirations
再执行:python manage.py migrate
再将default删去,即执行:name = models.CharField(max_length=50)
执行:python manage.py makemirations
再执行:python manage.py migrate
解决!
注意:在开发过程中,数据库同步误操作之后,难免会遇到后面不能同步成功的情况,解决这个问题的一个简单粗暴方法是把migrations目录下的脚本(除__init__.py之外)全部删掉,再把数据库删掉之后创建一个新的数据库,数据库同步操作再重新做一遍。
相关文章推荐
- You are trying to add a non-nullable field 'password' to userinfo without a default问题
- django在models.py新增表字段出现You are trying to add a non-nullable field 'message' to usermessage without a
- Django model :add a non-nullable field 'SKU' to product without a default; we can't do that
- 使用FABridge时,出现You are trying to call recursively into the Flash Player which is not allowed…错误的处理
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- 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?
- FATA[0000] (省略) Are you trying to connect to a TLS-enabled daemon without TLS?
- 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.
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- 在数据库中执行删除delete语句时出现:You are using safe update mode and you tried to update a table without a WHERE
- Windows环境下安装beautifulsoup4出现 'You are trying to run the Python 2 version of Beautiful Soup ....错误
- Django 在ForeignKey中出现 non-nullable field错误
- MySQL错误:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL easonjim
- 错误 You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- 数据库 safe You are using safe update mode and you tried to update a table without a WHERE
- 处理MySQL更新表时ErrorCode:1175.You are using safe update mode and you tried to update a table without a WHERE that uses a KEY