MySQL add foreign key completion constraint for table error can ' t create table ' Sfkbbs. #sql -513_25 ' (errno:150)

Source: Internet
Author: User

Code

Alter Table Add constraint   
Foreign Key References
on Delete Restrict on Update Restrict;

(constraint can be appended with the constraint name)

The reason for the error is that the IDs of the previous two tables are of different types, one when int, and one when bigint

Workaround when modifying the table,

Alter Table bigint;

You can change it after that.

Here is some information about MySQL

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
[Alter_specification [, Alter_specification] ...]
[Partition_options]

ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (Index_col_name,...)
Reference_definition

Topic:constraint
SQL supports foreign keys, which let you cross-reference related data across tables, and foreign key constraints, which he LP Keep this spread-out data consistent. The essential syntax for a FOREIGN KEY constraint definition in a CREATE TABLE or ALTER table statement looks like this:
[CONSTRAINT [Symbol]] FOREIGN KEY
[Index_name] (Index_col_name, ...)
REFERENCES tbl_name (Index_col_name,...)
[on DELETE Reference_option]
[on UPDATE Reference_option]

Reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION

See Also:online Help Create-table-foreign-keys

MySQL add foreign key completion constraint for table error can ' t create table ' Sfkbbs. #sql -513_25 ' (errno:150)

Related Article

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.