pgAdmin - 当尝试创建外键“引用”时没有给出任何选项
我有三个表:ModelingAgency.clients
、ModelingAgency.models
、ModelingAgency.Bookings
。所有三个表都有一个名为 id
的主键列。
表 bookings
有两列,分别引用 clients
和 models
。在 pgAdmin 中,当我尝试在 bookings
中为 clients
或 models
创建外键时,我会看到以下屏幕:
我忽略了什么这里?我是 PostgreSQL 的新手(这是我使用 PostgreSQL 的第一个测试项目——我一直使用 MySQL,偶尔使用 SQL Server),所以这可能是显而易见的事情(我只是没有看到它)。
编辑:这是根据要求的 DDL:
-- Table: "ModelingAgency.bookings"
-- DROP TABLE "ModelingAgency.bookings";
CREATE TABLE "ModelingAgency.bookings"
(
id integer NOT NULL DEFAULT nextval('"ModelingAgency.Bookings_id_seq"'::regclass),
"clientId" integer NOT NULL,
"modelId" integer NOT NULL,
"time" timestamp with time zone NOT NULL DEFAULT now(),
"location" character varying(100) NOT NULL DEFAULT 'No Location Selected'::character varying,
CONSTRAINT "bookingId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.bookings" OWNER TO "MyBatisTutorial";
-- Table: "ModelingAgency.clients"
-- DROP TABLE "ModelingAgency.clients";
CREATE TABLE "ModelingAgency.clients"
(
id integer NOT NULL DEFAULT nextval('"ModelAgency.clients_id_seq"'::regclass),
"name" character varying(45) NOT NULL,
CONSTRAINT "clientId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.clients" OWNER TO "MyBatisTutorial";
-- Table: "ModelingAgency.models"
-- DROP TABLE "ModelingAgency.models";
CREATE TABLE "ModelingAgency.models"
(
id serial NOT NULL,
"name" character varying(45) NOT NULL,
CONSTRAINT "modelId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.models" OWNER TO "MyBatisTutorial";
I have three tables: ModelingAgency.clients
, ModelingAgency.models
, ModelingAgency.Bookings
. All three tables have a primary key column called id
.
The table bookings
has two columns that reference clients
and models
. In pgAdmin when I try to create a foreign key in bookings
to either clients
or models
I get the following screens:
What am I overlooking here? I am new to PostgreSQL (This is my first test project with PostgreSQL -- I've always used MySQL and occasionally SQL Server) so it's probably something obvious (I just don't see it).
EDIT: Here is the DDL, as requested:
-- Table: "ModelingAgency.bookings"
-- DROP TABLE "ModelingAgency.bookings";
CREATE TABLE "ModelingAgency.bookings"
(
id integer NOT NULL DEFAULT nextval('"ModelingAgency.Bookings_id_seq"'::regclass),
"clientId" integer NOT NULL,
"modelId" integer NOT NULL,
"time" timestamp with time zone NOT NULL DEFAULT now(),
"location" character varying(100) NOT NULL DEFAULT 'No Location Selected'::character varying,
CONSTRAINT "bookingId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.bookings" OWNER TO "MyBatisTutorial";
-- Table: "ModelingAgency.clients"
-- DROP TABLE "ModelingAgency.clients";
CREATE TABLE "ModelingAgency.clients"
(
id integer NOT NULL DEFAULT nextval('"ModelAgency.clients_id_seq"'::regclass),
"name" character varying(45) NOT NULL,
CONSTRAINT "clientId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.clients" OWNER TO "MyBatisTutorial";
-- Table: "ModelingAgency.models"
-- DROP TABLE "ModelingAgency.models";
CREATE TABLE "ModelingAgency.models"
(
id serial NOT NULL,
"name" character varying(45) NOT NULL,
CONSTRAINT "modelId" PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "ModelingAgency.models" OWNER TO "MyBatisTutorial";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您发布的 DDL 代码,我发现您的表名称以错误的方式编写(这会导致 pgAdmin 出现问题):
它应该采用格式
"schema"."tableName"
:之后是对象浏览器看起来像这样(可能您需要首先使用 pgAdmin 或
CREATE SCHEMA
SQL 语句):这里是工作 DDL 代码(我省略了一些诸如
OIDS
和OWNER TO
之类的东西,但这对你的情况并不重要,顺便说一句,OIDS
是错误的默认):Looking into your posted DDL code I see that your table's names are written in wrong way (that causes your issue with pgAdmin):
It should be in format
"schema"."tableName"
:After that Object browser looks like this (probably you need to create schema first using easily pgAdmin or with
CREATE SCHEMA
SQL statement):Here is working DDL code (I omitted some things like
OIDS
andOWNER TO
, but that doesn't matter to your case, BTWOIDS
are false on default):