pgAdmin - 当尝试创建外键“引用”时没有给出任何选项

发布于 2024-11-19 16:42:43 字数 1884 浏览 1 评论 0原文

我有三个表:ModelingAgency.clientsModelingAgency.modelsModelingAgency.Bookings。所有三个表都有一个名为 id 的主键列。

bookings 有两列,分别引用 clientsmodels。在 pgAdmin 中,当我尝试在 bookings 中为 clientsmodels 创建外键时,我会看到以下屏幕:

屏幕一

屏幕二

我忽略了什么这里?我是 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:

Screen One

Screen Two

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-11-26 16:42:43

查看您发布的 DDL 代码,我发现您的表名称以错误的方式编写(这会导致 pgAdmin 出现问题):

"ModelingAgency.bookings"

它应该采用格式 "schema"."tableName"

"ModelingAgency"."bookings"

之后是对象浏览器看起来像这样(可能您需要首先使用 pgAdmin 或 CREATE SCHEMA SQL 语句):

在此处输入图像描述

这里是工作 DDL 代码(我省略了一些诸如 OIDSOWNER TO 之类的东西,但这对你的情况并不重要,顺便说一句,OIDS 是错误的默认):

DROP TABLE IF EXISTS  "ModelingAgency"."bookings";
CREATE TABLE "ModelingAgency"."bookings"
(
    id serial,
    "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)
);

DROP TABLE IF EXISTS "ModelingAgency"."clients";
CREATE TABLE "ModelingAgency"."clients"
(
    id serial,
    "name" character varying(45) NOT NULL,
    CONSTRAINT "clientId" PRIMARY KEY (id)
);

DROP TABLE IF EXISTS "ModelingAgency"."models";
CREATE TABLE "ModelingAgency"."models"
(
    id serial NOT NULL,
    "name" character varying(45) NOT NULL,
    CONSTRAINT "modelId" PRIMARY KEY (id)
)

Looking into your posted DDL code I see that your table's names are written in wrong way (that causes your issue with pgAdmin):

"ModelingAgency.bookings"

It should be in format "schema"."tableName":

"ModelingAgency"."bookings"

After that Object browser looks like this (probably you need to create schema first using easily pgAdmin or with CREATE SCHEMA SQL statement):

enter image description here

Here is working DDL code (I omitted some things like OIDS and OWNER TO, but that doesn't matter to your case, BTW OIDS are false on default):

DROP TABLE IF EXISTS  "ModelingAgency"."bookings";
CREATE TABLE "ModelingAgency"."bookings"
(
    id serial,
    "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)
);

DROP TABLE IF EXISTS "ModelingAgency"."clients";
CREATE TABLE "ModelingAgency"."clients"
(
    id serial,
    "name" character varying(45) NOT NULL,
    CONSTRAINT "clientId" PRIMARY KEY (id)
);

DROP TABLE IF EXISTS "ModelingAgency"."models";
CREATE TABLE "ModelingAgency"."models"
(
    id serial NOT NULL,
    "name" character varying(45) NOT NULL,
    CONSTRAINT "modelId" PRIMARY KEY (id)
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文