Mysqlerror: 150 error foreign key problem _ MySQL

Source: Internet
Author: User
Mysqlerror: 150 error foreign key problem Mysql foreign key

BitsCN.com

Mysql error: 150 foreign key error

ERROR 1005 (HY000): Can't create table '*****. frm' (errno: 150)

Problem

1. make sure that the referenced tables and fields exist;

2. the fields that make up the foreign key must be indexed (the fields that make up the foreign key must be the primary key in other tables );

3. two or more tables associated with foreign keys must be INNODB tables;

4. The field type (description) should be the same

One of the SQL statements exported from workbench cannot be inserted into the database. you can leave it as a record.

Both Article 1 and Article 4 are clear. Mark Article 1 and Article 3.

2. this problem occurs when an index is required for this field. Previously, the field associated with the foreign key is changed to another one, which is the primary key, but is associated, that is, the union index is created, in this case, setting up a foreign key is not supported by mysql on this key. Therefore, you must create an index on this key separately.

3. INNODB supports foreign keys. MyISAM engine does not support foreign keys.

Therefore, we mainly look at these two types of errors. The table created with the tool usually does not have 1 or 4 errors, and we hope to help people who see the article reduce the waste of time. Make a record.

BitsCN.com

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.