简体   繁体   English

SQL查询更改表MySql中的错误

[英]Error in SQL Query Alter Table MySql

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? 我可能做错了什么?

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? 在执行命令之前,它将禁用检查并允许您继续?

Yeah, don't you just love MySQL's awesome error messages. 是的,您不只是喜欢MySQL的出色错误消息。

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. 确保两个表中的Property_ID列具有完全相同的数据类型 That's how I have fixed similar errors for myself in the past. 这就是我过去为自己解决类似错误的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM