简体   繁体   English

PostgreSQL 错误:关系<Table>不存在

[英]PostgreSQL error: relation <Table> does not exist

I have created 2 tables in postgres, one of them seems to be fine but the other one returns the error: relation "series" does not exist.我在 postgres 中创建了 2 个表,其中一个似乎没问题,但另一个返回错误:关系“系列”不存在。 These 2 tables are completely the same, except for the primary key and some columns.除了主键和一些列之外,这两个表完全相同。 what seems to be the problem?似乎是什么问题? when the primary key is different, shouldnt that create table?当主键不同时,不应该创建表吗? ''' '''

CREATE TABLE Films
(
Fid varchar (3) NOT NULL DEFAULT '000' PRIMARY KEY,
Uiid varchar (3),
FOREIGN KEY (Uiid) REFERENCES Users(Uid)
ON DELETE SET Default
ON UPDATE CASCADE,

Ciid varchar (3),
FOREIGN KEY (Ciid) REFERENCES Cinemas(Cid)
ON DELETE SET Default
ON UPDATE CASCADE,

Aiid varchar (3),
FOREIGN KEY (Aiid) REFERENCES Actor(Aid)
ON DELETE SET Default
ON UPDATE CASCADE,

Diid varchar (3),
FOREIGN KEY (Diid) REFERENCES Director(Did)
ON DELETE SET Default
ON UPDATE CASCADE,

uComm varchar (15000),
FOREIGN KEY (uComm) REFERENCES UserComments(Commentss)
ON DELETE SET Default
ON UPDATE CASCADE,

FName char (20) NOT NULL,
FprodYear char(4) NOT NULL,
FRate RATE,
FGenre char(50) NOT NULL        
);

''' '''

CREATE TABLE Series
(
Sid varchar (3) NOT NULL DEFAULT '000' PRIMARY KEY,
Uiiid varchar (3),
FOREIGN KEY (Uiiid) REFERENCES Users(Uid)
ON DELETE SET Default
ON UPDATE CASCADE,
Ciiid varchar (3),
FOREIGN KEY (Ciiid) REFERENCES Cinemas(Cid)
ON DELETE SET Default
ON UPDATE CASCADE,

Aiiid varchar (3),
FOREIGN KEY (Aiiid) REFERENCES Actor(Aid)
ON DELETE SET Default
ON UPDATE CASCADE,

Diiid varchar (3),
FOREIGN KEY (Diiid) REFERENCES Director(Did)
ON DELETE SET Default
ON UPDATE CASCADE,

uCommm varchar (15000),
FOREIGN KEY (uCommm) REFERENCES UserComments(Commentss)
ON DELETE SET Default
ON UPDATE CASCADE,

SName char (20) NOT NULL,
SprodYear char(4) NOT NULL,
SRate RATE,
SGenre char(50) NOT NULL
);

Before this two tables have you created this tables:在这两个表之前,您已经创建了这些表:

  • Users用户
  • Cinemas电影院
  • Actor演员
  • Director导向器
  • UserComments用户评论

If you have not then both of this tables will not be created.如果没有,则不会创建这两个表。

Also please check have you created a type called RATE .另外请检查您是否创建了一个名为RATE的类型。

If you have already created tables I have mentioned and datatype RATE make sure you have primary key's in this table so your foreign key's can reference them.如果您已经创建了我提到的表和数据类型 RATE,请确保您在此表中有主键,以便您的外键可以引用它们。

Then, if you have done all of this do check the comment from @TheImpaler: "DEFAULT '000' on a primary key (or any key) makes little sense.".然后,如果您已完成所有这些操作,请检查来自@TheImpaler 的评论:“主键(或任何键)上的 DEFAULT '000' 毫无意义。”。

Also, when you have primary key on the column you do not need NOT NULL constraint.此外,当您在列上有主键时,您不需要 NOT NULL 约束。

After all of that you will have two codes that work: https://dbfiddle.uk/?rdbms=postgres_12&fiddle=a91b77594583e6768360709ef7a9f494毕竟,您将有两个有效的代码: https : //dbfiddle.uk/?rdbms=postgres_12&fiddle=a91b77594583e6768360709ef7a9f494

After commenting with the OP I have discovered that he can create the table by referencing the schema before the table name like this:在对 OP 发表评论后,我发现他可以通过在表名之前引用架构来创建表,如下所示:

create table schema_name.Series...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM