Mysql foreign key creation failure

Source: Internet
Author: User


CREATE persons: create table 'persons '('Id _ P' int (11) not null AUTO_INCREMENT, 'lastname' varchar (10) default null, 'firstname' varchar (10) default null, 'address' varchar (50) default null, 'city' varchar (10) default null, primary key ('Id _ p'); www.2cto.com CREATE a TABLE orders: create table 'Orders '('Id _ o' int (11) not null AUTO_INCREMENT, 'orderno' int (11) not null, 'Id _ P' int (11) not null, p Rimary key ('Id _ o'), foreign key ('Id _ p') REFERENCES 'persons '('Id _ p'); Use the show create table orders statement, query the orders Information and find that the foreign key is not created successfully. I checked some information and finally found the reason. Mysql creates a TABLE of the MyISAM type by default. You must specify the TABLE type as innodb: www.2cto.com create table 'Orders '('Id _ o' int (11) not null AUTO_INCREMENT, 'orderno' int (11) not null, 'Id _ P' int (11) not null, primary key ('Id _ o '), foreign key ('Id _ p') REFERENCES 'persons '('Id _ p') ENGINE = InnoDB; however, the following ERROR message is displayed: ERROR 1005 (HY000 ): can't create table 'test. orders '(errno: 150) specifies the persons Table type as innodb. To sum up the following situations: 1. foreign keys and referenced Foreign keys are of different types. For example, integer and double2. the column to be referenced cannot be found. the character encoding of the table is different. 4. different data engine types, such as innodb and myisam author gavinr

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.