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