MySQL Error Code: 1005

走远了吗. 提交于 2019-12-05 20:18:51

Most of such error will be related to data type miss match or so.. If you could go through these links.. it might help you i guess.. Check-this ... also Check-this

As they say in the second link:

The first place you should look is whether the data types agree between the foreign key and primary key columns.

mysql> SHOW engine innodb STATUS;

------------------------
LATEST FOREIGN KEY ERROR
------------------------
100130 17:16:57 Error IN FOREIGN KEY CONSTRAINT OF TABLE sampledb/#sql-4a0_2:
FOREIGN KEY(member_type)
REFERENCES common_lookup(common_lookup_id):
Cannot find an INDEX IN the referenced TABLE WHERE the
referenced COLUMNS appear AS the FIRST COLUMNS, OR COLUMN types
IN the TABLE AND the referenced TABLE do NOT MATCH FOR CONSTRAINT.

make sure that one of the key field that you are trying to reference does not have an index and/or is not a primary key. and the two key fields type and/or size should be an exact match also make sure that both tables are InnoDB tables.

This can happen due to two reasons

  1. Table creation failed because a foreign key constraint was not correctly formed or
  2. Datatype mismatch in the constraints.

the below link would be helpful

http://dev.mysql.com/doc/refman/5.0/en/innodb-error-codes.html

Last time I encountered this, it was the constraints: referenced table key type was 'int' and referring table had 'unsigned int' referring field by mistake, instead of int.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!