oracle ORA-00904: "ID": 无效标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19339464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:00:22  来源:igfitidea点击:

ORA-00904: "ID": invalid identifier

sqloracleforeign-keysddl

提问by user2199351

Trying to create a table with a foreign key. I keep getting ORA-00904error. What am I doing wrong. Is it because table of the foreign key is not yet created ?

尝试使用外键创建表。我不断收到ORA-00904错误。我究竟做错了什么。是不是因为外键表还没有创建?

CREATE TABLE ingredients( 
   ingredient_id       number(2,0),
   ingredient          VARCHAR2(55) NOT NULL,
   quantity_required   VARCHAR2(15) NOT NULL,
   optional_ingredient VARCHAR2(30) NOT NULL,
   CONSTRAINT pk_ingr_id PRIMARY KEY(ingredient_id),
   CONSTRAINT fk_ingredient_list FOREIGN KEY(id) REFERENCES ingredient_list(id)
);

回答by Mureinik

Take a look at the following line:

看看下面这行:

CONSTRAINT fk_ingredient_list FOREIGN KEY(id) REFERENCES ingredient_list(id)

Your table has no column named "id". I assume you meant to write

您的表没有名为“id”的列。我假设你打算写

CONSTRAINT fk_ingredient_list FOREIGN KEY(ingredient_id) REFERENCES ingredient_list(id)

EDIT:
Additionally, as you suspected yourself, if you want to reference the ingredient_listtable, you must create it before creating the ingredientstable that references it.

编辑:
此外,正如您自己怀疑的那样,如果您想引用该ingredient_list表,则必须在创建ingredients引用它的表之前创建它。

回答by incakola

We never know but in my case I had this exception no matter what name I gave my column. I had a library with EF which pointed on the proper database. The entities were correct.

我们永远不知道,但就我而言,无论我给我的专栏起什么名字,我都有这个例外。我有一个带有 EF 的库,它指向正确的数据库。实体是正确的。

But on the client part (a web application), the connection string pointed to another database! A stupid mistake, it was hard to pinpoint this silly misgave....

但是在客户端(Web 应用程序)上,连接字符串指向另一个数据库!一个愚蠢的错误,很难查明这个愚蠢的错误......

So please have a look at the connection string FIRST :)

所以请先看看连接字符串:)