如何解决为什么我得到“没有唯一的约束匹配给定键的引用表...”错误
根据此SO Answer,没有给引用表“ ...”的给定键匹配的唯一约束。是您在调用外键引用时遇到的错误列不是唯一的。但是为什么我会在这里得到这个错误?
postgres=# create database example;
CREATE DATABASE
postgres=# \c example
You are now connected to database "masterdb" as user "postgres".
masterdb=# create table foo(
id bigserial
);
CREATE TABLE
masterdb=# create table bar (
id bigserial,foo_fid bigint not null references foo (id)
);
ERROR: there is no unique constraint matching given keys for referenced table "foo"
解决方法
您的表必须在被引用的列上具有唯一索引:
CREATE TABLE foo(
id BIGSERIAL UNIQUE
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。