Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle create table with foreign key error - Invalid Identifier

I'm getting an error saying invalid identifier when I try to add this table. Its been bugging me for too long now so I thought I'd ask.

CREATE TABLE HORSE 
(  
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40), 
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id) 
);

The error message is;

Error at Command Line:34 Column:37
Error report:
SQL Error: ORA-00904: "BREED_ID": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Thanks and sorry for asking what is probably a really dumb question.

like image 730
pjmil Avatar asked Nov 20 '25 16:11

pjmil


1 Answers

You need breed_id in HORSE table

CREATE TABLE HORSE 
(  
horse_id numeric PRIMARY KEY,
horse_name character(30) not null,
horse_gender character(1) not null,
horse_height decimal not null,
horse_image character(40), 
breed_id numeric null
CONSTRAINT horse_breed FOREIGN KEY (breed_id) REFERENCES breed(breed_id) 
);
like image 159
Robert Avatar answered Nov 22 '25 05:11

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!