我正在尝试从表中选择一行:
但是当我尝试强制执行第一个约束时遇到了问题。
以下是对整数按预期工作的所有内容:首先,创建如下所示的表:
t1
+----+---------+
| id | content |
+----+---------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+---------+
Run Code Online (Sandbox Code Playgroud)
和
t2
+----+---------+
| id | t1_id |
+----+---------+
| 1 | 1 |
+----+---------+
Run Code Online (Sandbox Code Playgroud)
postgres=# create table t1(id int, content varchar(10), primary key (id));
CREATE TABLE
postgres=# create table t2(id int, t1_id int, foreign key (t1_id) references t1(id));
CREATE TABLE
postgres=# insert into t1 values (1, 'a');
INSERT 0 …Run Code Online (Sandbox Code Playgroud)