'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 ...
随机推荐
- Luffy项目:2、项目需求(2),项目库的创建,软件开发目录,Django配置文件介绍
目录 Luffy项目 一.Luffy项目需求(2) 1.后台日志封装 2.全局异常处理.封装 3.封装Response对象 二.Luffy项目数据库创建 1.创建用户数据库 2.使用项目链接数据库 2 ...
- kubernetes client-go功能介绍
原味地址 https://haiyux.cc/2023/02/26/k8s-client-go/ client-go是什么? client-go是Kubernetes官方提供的Go语言客户端库,用于与 ...
- 添加weui-miniprogram
1.打开根目录 npm init npm install weui-miniprogram --save 2.打开project.config.json 设置 "packNpmManuall ...
- LeetCode-593 有效的正方形
来源:力扣(LeetCode)链接:https://leetcode.cn/problems/valid-square 题目描述 给定2D空间中四个点的坐标 p1, p2, p3 和 p4,如果这四个 ...
- java环境变量(Windows 11)
1.下载JDK,之后安装 建议安装java8或者java11,稳定,大家都在用 下载网址:https://www.oracle.com/java/technologies/downloads/#jav ...
- 179. 最大数 (Medium)
问题描述 179. 最大数 (Medium) 给定一组非负整数 nums,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数. 注意: 输出结果可能非常大,所以你需要返回一个字符串而不是整数 ...
- Deer_GF之IOS出热更包
Hi,今天介绍一下Deer_GF_Wolong,框架基于HybridCLR热更新技术,出IOS热更包 首先我们需要准备的工作: 环境:Mac Unity 版本 2021.3.1f1c1 热更方案:Hy ...
- 打卡ts day01 数据类型,类
一,环境 1 新增的数据类型和部分语法,没有办法在浏览器和node 中执行,需要安装typescript 环境 安装:npm i -g typescript 成功:tsc -v 2 在浏览器中使用ts ...
- javascript中的二进制运算符
javascript的二进制运算符用于直接对二进制位进行计算,好处是速度快,缺点是不直观. 位运算符只对整数起作用,如果一个运算子不是整数,则会转换成整数后再执行;我们都知道javascript的数值 ...
- WSL2安装nvm并配置npm镜像源
1.下载安装脚本并执行 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash 2.关闭命令行后 ...