'xxx' must be unique because it is referenced by a foreign key.
'xxx' must be unique because it is referenced by a foreign key.
原因:在绑定外键时,对应的外键字段的没有设置成唯一。
说明:在定义字段时,需要在被关联字段参数内添加unique=True
错误示例:
# UserInfo
Class UserInfo(models.Model):
name = models.CharField(verbose_name="姓名",max_length=32)
# TaskInfo
class TaskInfo(models.Model):
worker = models.ForeignKey(verbose_name="负责人",to="UserInfo",to_field="name",on_delete=models.CASCADE)
正确示例:
# UserInfo
Class UserInfo(models.Model):
name = models.CharField(verbose_name="姓名",max_length=32,unique=True)
'xxx' must be unique because it is referenced by a foreign key.的更多相关文章
- Could not drop object 'student' because it is referenced by a FOREIGN KEY constraint
1. Find foreign keys SELECT * FROM sys.foreign_keys WHERE referenced_object_id = object_id('Student' ...
- [Err] 1701 - Cannot truncate a table referenced in a foreign key constraint
1.SET FOREIGN_KEY_CHECKS=0; 2.DELETE FROM ACT_RE_DEPLOYMENT where 1=1; 或者 truncate table ACT_RE_DEPL ...
- [MySQL数据库之表的约束条件:primary key、auto_increment、not null与default、unique、foreign key:表与表之间建立关联]
[MySQL数据库之表的约束条件:primary key.auto_increment.not null与default.unique.foreign key:表与表之间建立关联] 表的约束条件 约束 ...
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误 SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM ORA-02266: unique/prim ...
- The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....
遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....,查找的 ...
- [Eclipse]The type XXX cannot be resolved. It is indirectly referenced from required .class files
在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...
- ORA-02273: this unique/primary key is referenced by some foreign keys
关于ORA-02273错误,以前还真没有仔细留意过.昨天遇到了这个问题,遂顺便总结一番,以后遇到这类问题就可以直接用下面方案解决.如下所示,我们首先准备一下测试环境. CREATE TABLE TES ...
- 在eclipse中新建java问题报错:The type XXX cannot be resolved. It is indirectly referenced from required .class files
在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...
- django migrate报错:1005 - Can't create table xxx (errno: 150 "Foreign key constraint is incorrectly formed")
自从mysql升级,以及使用mariaDB以来,很多不曾更新django中model的外键, 今天,按以前的思路写完外键之后, migrate命令报错: 1005 - Can't create tab ...
- 数据库六大约束用法:主键(primary key)、外键(foreign key)、非空(not null)、默认(default)、检查(check)、唯一(unique)
1. 数据库有六大约束 主键(primary key) 外键(foreign key):被参照的键必须有唯一约束或是主键 非空(not null) 默认(default) 检查(check):orac ...
随机推荐
- day08-MyBatis的关联映射02
MyBatis的关联映射02 3.一对多 3.1基本介绍 mybatis – MyBatis 3 | XML 映射器 多对一关系也是一个基本的映射关系,多对一,也可以理解为一对多.例如: User-- ...
- js高德地图添加点Marker,添加线段Polyline,添加一个区域Polygon(面)
高德地图JS API 实例 亲测可用 参考网站=> 阿里云数据可视化平台(下载json用的):http://datav.aliyun.com/portal/school/atlas/area_ ...
- lama-cleaner全部命令行参数
usage: main.py [-h] [--host HOST] [--port PORT] [--config-installer] [--load-installer-config] [--in ...
- 增加select的option之间的间距
直接设置option的上下内边距即可,即padding-top和padding-bottom.
- Centos7.6centOS7.8多网卡多IP配置
1.进入网卡配置文件 cd /etc/sysconfig/network-scripts/2.创建新网卡的配置文件 ifcfg-eth1 cp ifcfg-eth0 ifcfg-eth1这样副网卡配置 ...
- 关于我在安装2.6.9版本bochs虚拟机时遇到的问题以及解决过程
更新于:2019.7.2 在阅读<一个64位操作系统的设计与实现>过程中,搭建实验环境遇到的诸多困难. 本人的实验环境:vmware15.0 下安装有kali-liunx虚拟机里进行的安装 ...
- 学习lua-06,异常提示,错误处理
addNum = function(a, b) assert(type(a) == 'string','a必须是一个字符串') assert(type(b) == 'string','b必须是一个字符 ...
- file、blob、base64相互转换
blob blob转file const blob = '.....' const file = new File([blob], 'name.wav', {type: 'audio/wav'}); ...
- java-javaSE-集合类
集合类结构 集合类的基本接口是 Collection 和 Map Collection 向下派生出 Set List Queue 等接口 Map 向下派生出 HashMap LinkedHashMap ...
- ipvsadm DR模型的实现方式
DR模型的lvs ----在实现DR模型的时候所有RS都要屏蔽掉ARP请求的响应 实现方法:1.可以用路由器绑定静态VIP:MAC(DVIP)2.可以使用arptables3.可以使用 kernel ...