abc32112
abc32112

Reputation: 2527

ERROR 1215 (HY000): Cannot add foreign key constraint

I'm following a tutorial in Sams Teach Yourself SQL and in pretty much the first example, I'm stuck:

Here's what I'm supposed to enter:

create table employee_pay_tbl ( 
emp_id varchar(9) not null primary key, 
position varchar(15) not null, 
date_hite date, 
pay_rate decimal(4,2), 
date_last_raise date, 
salary decimal(8,2), 
bonus decimal(6,2), 
constraint emp_fk foreign key (emp_id) references emplyee_tbl (emp_id) );

Result: ERROR 1215 (HY000): Cannot add foreign key constraint

Sigh. So now what? I haven't got the first clue where to start looking.

Upvotes: 2

Views: 1668

Answers (1)

span
span

Reputation: 5624

Looks like you have a typo in your "references" clause. You're missing an o in emplyee_tbl.

Try this:

create table employee_pay_tbl ( 
emp_id varchar(9) not null primary key, 
position varchar(15) not null, 
date_hite date, 
pay_rate decimal(4,2), 
date_last_raise date, 
salary decimal(8,2), 
bonus decimal(6,2), 
constraint emp_fk foreign key (emp_id) references employee_tbl (emp_id) );

Also make sure you have created the table you are referencing.

Upvotes: 2

Related Questions