Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
来源:互联网 发布:sql server 2005 教程 编辑:程序博客网 时间:2024/06/05 08:31
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之外)全部删掉,再把数据库删掉之后创建一个新的数据库,数据库同步操作再重新做一遍。
0 0
- Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
- 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
- Docker Are you trying to connect to a TLS-enabled daemon without TLS?
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses
- 数据库 safe You are using safe update mode and you tried to update a table without a WHERE
- 在数据库中执行删除delete语句时出现:You are using safe update mode and you tried to update a table without a WHERE
- The project you are trying to remove is currently deployed to a running application server.解决方案
- 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
- 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
- MySQL错误:You are using safe update mode and you tried to update a table without a WHERE that uses a K
- "The file you are trying to open, '[filename]', is in a different format" Excel Error
- excel报表导出报错The workbook you are trying to save has the same name as a currently open workbook
- you are trying to reader the global image variable as a react element.you probably forgot to require
- 关于"Are you missing a call to unregisterReceiver()? "错误
- 【异常处理】Are you missing a call to unregisterReceiver()?
- struts2学习总结
- 图形
- POJ 1013 Counterfeit Dollar 笔记 模拟
- 详解网页中的瀑布流显示效果
- 这是一个基于Vue2实现的网易云音乐MV的webapp。
- Django数据库操作中You are trying to add a non-nullable field 'name' to contact without a default错误处理
- LintCode 翻转二叉树
- R语言矢量数据空间分析一:入门及rgeo包简介
- 关于C++类(一)
- hive合并小文件
- 如何查看Linux下面某一个目录下所有的隐藏文件和文件夹
- 递归(recursion)
- KMP模式串匹配模板
- linux tcp三路握手详解