How to solve the error message "error150" in the MySQL tutorial

Source: Internet
Author: User
Tags mysql tutorial
You cannot create one. the error of the frm file seems to imply an error in the file permission of the operating system or other reasons, but in fact, none of these are actually. In fact, this mysql error has been reported as a mysql bug and has been found in the mysql developer list for many years. However, this is misleading. In many instances

You cannot create one. the error of the frm file seems to imply an error in the file permission of the operating system or other reasons, but in fact, none of these are actually. In fact, this mysql error has been reported as a mysql bug and has been found in the mysql developer list for many years. However, this is misleading. In many instances

You cannot create one. the error of the frm file seems to imply an error in the file permission of the operating system or other reasons, but in fact, none of these are actually. In fact, this mysql error has been reported as a mysql bug and has been found in the mysql developer list for many years. However, this seems misleading.

In many instances, this error occurs because mysql has never been able to support the problem, unfortunately, it does not specify which problem will lead to the above error. Below I will list the common causes of this terrible 150 error, and I sorted it by the possibility.

Known causes:

1. the type or size of two fields are not strictly matched. For example, if one field is INT (10), the foreign key must be set to INT (10) instead of INT (11) it cannot be TINYINT. you must use the SHOW command to check the field size, because some query browsers sometimes display both int (10) and int (11) as integer. In addition, you must determine whether one of the two fields is SIGNED and the other is UNSIGNED. The two fields must be exactly consistent.

2. You have not created an index for one of the foreign keys you are trying to reference, or it is not a primary key. If one of them is not a primary key, you must create an index for it.

3. The foreign key name is an existing key value. In this case, you should check your database to ensure that the foreign key name is unique, or you can add a few random characters after the key name to test whether it is the cause.

4. One or two tables are MyISAM engine tables. To use foreign key constraints, they must be InnoDB Engine (in fact, if both tables are MyISAM engine tables, this error does not occur at all, but does not generate foreign keys). You can set the engine type of the table through the query browser.

5. You may have SET the on delete set null, but the related key field is SET to the nots null value. You may modify the cascade attribute value or set the field attribute to allow null to fix this bug.

6. Make sure that your Charset and Collate options are consistent at the table level and field level.

7. You may have set a default value for the foreign key, for example, default = 0.

8. In this relationship, one of the fields is one of the hybrid key values, and it does not have its own independent index. In this case, you must create an independent index for it.

9. syntax errors in the ALTER Declaration

1. The foreign key reference types are different. The primary key is an int foreign key is a char

2. The column referenced in the master table cannot be found.

3. The character encoding of the primary key and the foreign key is inconsistent.

4. If you want to create a foreign key, you must first create an index. An error occurs if no index is created.

My problem solution is to add the following sentence after SQL, OK! Script imported successfully

ENGINE = innodb default charset = utf8;

Replace charset with the character set of your primary key table!

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.