database - Oracle (ORA-02270) : no matching unique or primary key for this column-list error -


i have 2 tables, table job , table user, here structure

 create table job  (    id       number not null ,    userid   number,    constraint b_pk primary key ( id ) enable  );   create table user  (    id       number not null ,    constraint u_pk primary key ( id ) enable  ); 

now, want add foreign key constraint job referencing user table,

alter table job add constraint fk_userid foreign key(userid) references user(id); 

this throws oracle (ora-02270) : no matching unique or primary key column-list error, doing investigation appears need have either unique key or primary key constraint on userid cannot have 1 userid can have multiple jobs associated him, thoughts or suggestions on how fix issue?

researched ora-02270 , so related question

the ora-2270 error quite simple: happens when columns reference in foreign key not match primary key or unique constraint on parent table. common reasons are

  • the parent lacks constraint altogether
  • the parent table's constraint compound key , haven't referenced columns in foreign key statement.

neither appears case in posted code. that's red herring, because code does not run have posted it. judging previous edits presume not posting actual code simplified example. unfortunately in process of simplification have eradicated whatever causing ora-2270 error.

because, if fix code runs, - er - runs. way.

sql> create table job  (    id       number not null ,    userid   number,    constraint b_pk primary key ( id ) enable  );  2    3    4    5    6    table created.  sql> create table user  (    id       number not null ,    constraint u_pk primary key ( id ) enable  );  2    3    4    5   create table user              * error @ line 1: ora-00903: invalid table name   sql>  

so, statement failed because user reserved keyword, , cannot name table user. let's fix that:

sql> 1   1* create table user sql> s   1* create table users sql> l   1  create table users   2   (   3     id       number not null ,   4     constraint u_pk primary key ( id ) enable   5*  ) sql> r   1  create table users   2   (   3     id       number not null ,   4     constraint u_pk primary key ( id ) enable   5*  )  table created.  sql> alter table job add constraint fk_userid foreign key(userid) references users(id);     table altered.  sql>  

and lo! no ora-2270 error.

so, there's not can here further. have bug in code. can post code here , 1 of can spot mistake. or can check own code , discover yourself.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -