MYSQL Create constraint foreign key faild.trouble shooting method share

Source: Internet
Author: User

Mysql> CREATE TABLE tb_test (id int (1) NOT NULL auto_increment primary key,action_id Int (TEN) not Null,error_code int. 0) NOT NULL default 0,desc_key varchar (+) NOT null default ' Audit.log.default ', INDEX (action_id), constraint ' Fk_actionid ' Foreign key (' action_id ') references ' tb_tab1 ' (' action_id '));
ERROR 1215 (HY000): Cannot add foreign KEY constraint
Mysql>

The positioning method is as follows:

SHOW ENGINE INNODB STATUS:

LATEST FOREIGN KEY ERROR
------------------------
2016-01-29 08:45:15 7f5b11b09700 Error in FOREIGN key constraint of table auditdb/tb_test:
Foreign key (' action_id ') references ' tb_tab1 ' (' action_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 does not match for constraint.
Note that the internal storage type of ENUM and SET changed in
Tables created with >= InnoDB-4.1.12, and such columns in old tables
Cannot is referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
For correct foreign key definition.

Very detailed

Mysql Create constraint foreign key faild.trouble shooting method share

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.