ORA-00904: “ID”: invalid identifier

◇◆丶佛笑我妖孽 提交于 2019-12-10 09:54:53

问题


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

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)
);

回答1:


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

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_list table, you must create it before creating the ingredients table that references it.




回答2:


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.

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....

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



来源:https://stackoverflow.com/questions/19339464/ora-00904-id-invalid-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!