0

I get an error when executing the below query:

ALTER TABLE property_res_details 
ADD CONSTRAINT PropertyIdLink FOREIGN KEY ( Property_ID )  
REFERENCES properties( Property_ID )  ON DELETE CASCADE ;


#1005 - Can't create table './resfi/#sql-10e1_8df.frm' (errno: 150)

What might I be doing wrong?

2 Answers 2

2

This page might give a clue as to what's going on...

Since you're adding a foreign key, it sounds relevant. It suggests you try

SHOW ENGINE INNODB STATUS;

to see the latest constraint error which may cause the error you're seeing.

Maybe if you try

SET FOREIGN_KEY_CHECKS = 0; 

before your command, it will disable the checks and allow you to continue?

Sign up to request clarification or add additional context in comments.

1 Comment

You saved my day with this link. Thanks. I spend hours of investigating why the create fails.
0

Yeah, don't you just love MySQL's awesome error messages.

ADD CONSTRAINT PropertyIdLink FOREIGN KEY ( Property_ID )  
REFERENCES properties( Property_ID ) ON DELETE CASCADE;

Make sure that the Property_ID columns have the exact same datatype in both tables. That's how I have fixed similar errors for myself in the past.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.