- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个表“Persona”(人)和“Dona”(女性),我想更改第三个名为“Baptisme”(洗礼)的表,但我遇到了一些问题。
这些是我的表格:
CREATE TABLE baptismes.Persona (
id SERIAL PRIMARY KEY,
nom VARCHAR(255),
nom_complementari1 VARCHAR(255),
nom_complementari2 VARCHAR(255),
nom_complementari3 VARCHAR(255),
nom_complementari4 VARCHAR(255),
cognom1 VARCHAR(255),
cognom2 VARCHAR(255),
lloc_naixement VARCHAR(255) REFERENCES baptismes.Poblacio(nom),
data_naixement baptismes.Data,
alies VARCHAR(255),
sexe CHAR(1),
difunt BOOLEAN
);
CREATE TABLE baptismes.Dona (
cognom_marit_actual VARCHAR(255),
cognom_marit_anterior VARCHAR(255)
) INHERITS (baptismes.Persona);
CREATE TABLE baptismes.Baptisme (
id SERIAL PRIMARY KEY,
...
);
Baptisme 有更多属性,但它们在这里并不重要。
我想做的是:
ALTER TABLE baptismes.baptisme
ADD COLUMN mare INTEGER REFERENCES baptismes.Dona(id);
但这给了我以下错误:
ERROR: no hay restricción unique que coincida con las columnas dadas en la tabla referida «dona»
********** Error **********
ERROR: no hay restricción unique que coincida con las columnas dadas en la tabla referida «dona»
SQL state: 42830
英文:“没有唯一约束与引用表 <> 的给定键匹配”。
我无法理解,因为 Dona 从 Persona (id) 获取 PK,所以它应该是 UNIQUE
。
有人可以帮帮我吗?谢谢!
最佳答案
唉,这是一个documented不足:
5.8.1. Caveats
A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. This is true on both the referencing and referenced sides of a foreign key constraint.
- If we declared
cities.name
to beUNIQUE
or aPRIMARY KEY
, this would not stop the capitals table from having rows with names duplicating rows in cities. And those duplicate rows would by default show up in queries from cities. In fact, by default capitals would have no unique constraint at all, and so could contain multiple rows with the same name. You could add a unique constraint to capitals, but this would not prevent duplication compared to cities.
所以,您的问题是 dona.id
没有唯一约束。我认为您可以在 create table 语句中声明一个——或者通过之后更改表来声明。
关于sql - PostgreSQL 错误 : there is no unique constraint matching given keys for referenced table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29704604/
我正在查看 SQL Server 2008 的 AdventureWorks 示例数据库,我在他们的创建脚本中看到他们倾向于使用以下内容: ALTER TABLE [Production].[Prod
我目前正在使用 PostgreSQL 9.5,想知道是否有可能在 ON CONFLICT ON CONSTRAINT 语句中包含 2 个约束的名称。我的sql如下 INSERT INTO LIVE.T
使用 htmlhelpers 可以限制你的助手将绑定(bind)到什么类型 public static HtmlString DatePicker(this HtmlHelper html,
我使用的是 Symfony 2.5,我的 Model 类如下: /** * @UserAssert\UserPasswordReset */ class ResetPassword { /** *
我有 3 个 View :A、B、C。 (A 和 B 的高度相等)开始时 B 的可见性消失,C 的顶部约束是 A 的底部,因此 C 出现在 A 下方。一段时间后,我将 A 的可见性更改为消失,将 B
在 Dojo NumberTextBox 的文档中,措辞引用了“Dojo 约束语言”,甚至包括有用的 link .不幸的是,链接指向的页面仅显示 this document has been depr
在我的表中,我有一个唯一的约束。在 hibernate 中,当我添加一个违反该约束的项目时,我想捕获它,因此它将更新而不是创建一个项目。 当我没有设置 try-catch block 时 up
我正在尝试在“或”UILabel 附近添加两条 1 像素线(由 UIViews 组成)。 除了我从 Interface Builder 中的第一张图片收到警告外,一切看起来都很好并且按预期工作: Le
我已经开始学习安卓了。我正在尝试使用 Google Map API。每次我尝试启动我的应用程序时,它都会崩溃,经过调查,我在 build.gradle 文件中发现了一个通知。 Please refer
我有自定义约束: @Target({FIELD, METHOD}) @Retention(RetentionPolicy.RUNTIME) @ConstraintComposition(Composi
我正在将 Graphql 服务器与 Prisma 一起使用。但是当我尝试运行代码时出现此错误我正在使用 const { GraphQLServer } = require('graphql-yoga'
更新到 com.android.support.constraint:constraint-layout:1.1.0 之后 约束布局崩溃说: All children of constraint la
我在 Xcode 10 中工作,在尝试向我的 View 添加一些非常简单的约束时遇到了一些错误。 我有一个 UICollectionViewCell,我正在向其添加一个 UIStackView。我调整
尝试在 Laravel 上创建一个待办事项列表应用程序,但是当我尝试单击按钮创建一个新的待办事项列表时,出现此错误: SQLSTATE[23000]: Integrity constraint vio
我正在编写一个基于网格的 View ,使用以下代码动态添加 NSLayoutConstraints for (x, column) in enumerate(board) { for (y,
我正在尝试使用 Constraint composition并希望为每个复合约束定义组,如下例所示:- 复合约束 @Target({ ElementType.FIELD, Elemen
我有一些添加了外键约束的表。它们与代码生成一起使用,以在生成的存储过程中设置特定的联接。 是否可以通过在事务中调用多个删除来覆盖这些约束,特别是 C# 中的“TransactionScope”,或者绝
我需要向现有 SQL Server 表添加约束,但前提是该表尚不存在。 我使用以下 SQL 创建约束。 ALTER TABLE [Foo] ADD CONSTRAINT [FK_Foo_Bar] FO
这是我的总输出: Executing SQL script in server ERROR: Error 1215: Cannot add foreign key constraint CREATE
我正在增加 Facebook SDK 登录按钮 (FBSDKLoginButton) 的大小。 Facebook SDK 源代码向 FBSDKLoginButton 添加了一个约束,height =
我是一名优秀的程序员,十分优秀!