简体   繁体   English

错误:没有唯一约束匹配给定键的引用表

[英]ERROR: there is no unique constraint matching given keys for referenced table

I am getting an error when i create my tabels. 创建表格时出现错误。 The problem is that AssCode is not unique, so i can set it to unique, the combination of courseCode and AssCode is unique, thats why they are set as primary keys. 问题在于,AssCode不是唯一的,因此我可以将其设置为唯一,courseCode和AssCode的组合是唯一的,这就是为什么将它们设置为主键的原因。 I am using postgressql 我正在使用postgressql

here is the error: 这是错误:

ERROR: there is no unique constraint matching given keys for referenced table "assignments" SQL state: 42830 错误:没有唯一约束匹配给定键的引用表“ assignments” SQL状态:42830

here is my code: 这是我的代码:

CREATE TABLE Teachers (
    BSN int primary key,
    Surname varchar(40) NOT NULL,
    Name varchar(40) NOT NULL   
);

CREATE TABLE Courses  (
    CourseCode varchar(10) primary key,
    Name varchar(20) NOT NULL
);

CREATE TABLE Assignments (
    CourseCode varchar(10) REFERENCES Courses ON DELETE CASCADE,
    AssCode varchar(10),
    primary key(CourseCode,AssCode),
    DependOn varchar(10),
    Year date,  
    week int
);

CREATE TABLE WorkOn ( 
    BSN int REFERENCES Teachers(BSN),
    CourseCode varchar(10)  REFERENCES Assignments(CourseCode),
    AssCode varchar(10) REFERENCES Assignments(AssCode),
    primary key (CourseCode,BSN,AssCode)
 );

I found the answer: 我找到了答案:

CREATE TABLE WorkOn ( 
    BSN int primary key REFERENCES Teachers(BSN),   
    CourseCode varchar(10),
    AssCode varchar(10),    
    foreign key (CourseCode, AssCode) references Assignments (CourseCode, AssCode)
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有唯一约束匹配给定引用表的键 - No unique constraint matching given keys for referenced table PSQL错误,没有唯一约束匹配给定表引用的键 - PSQL Error there is no unique constraint matching given keys for referenced table 错误:没有唯一约束匹配给定键的引用表“bar” - ERROR: there is no unique constraint matching given keys for referenced table "bar" 远离错误:没有唯一约束匹配引用表的给定键 - Away around Error: There is no unique constraint matching given keys for referenced table Postgresql错误:没有唯一约束匹配给定键的引用表 - Postgresql ERROR: there is no unique constraint matching given keys for referenced table PostgreSQL错误:没有唯一约束匹配给定键的引用表 - PostgreSQL Error: there is not unique constraint matching given keys for referenced table 错误:没有唯一约束匹配给定表的键 - ERROR: No unique constraint matching given keys for referenced table 如何修复错误“没有唯一约束匹配引用表的给定键” - How to fix error "there is no unique constraint matching given keys for referenced table" "错误:没有唯一约束匹配引用表“事件”的给定键" - error: there is no unique constraint matching given keys for referenced table "incident" 无法解释此错误:没有与引用表的给定键匹配的唯一约束 - Unable to explain this error: there is no unique constraint matching given keys for referenced table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM