2

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";
4

1 回答 1

3

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

"ModelingAgency.bookings"

它应该是格式"schema"."tableName"

"ModelingAgency"."bookings"

之后对象浏览器看起来像这样(可能您需要先使用轻松 pgAdmin 或使用CREATE SCHEMASQL 语句创建模式):

在此处输入图像描述

这是有效的 DDL 代码(我省略了一些类似OIDSand的内容OWNER TO,但这对您的情况无关紧要,BTWOIDS默认为 false):

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)
)
于 2011-07-12T22:27:38.417 回答