The CREATE table does not support the primary foreign key, the ability to add foreign keys succeeds, but foreign key constraints are not possible. Check data found that the default engine for MySQL is MyISAM, foreign keys are not supported and need to be modified to INNODB
Before modification:
1 Create Table2 3 CREATE TABLE' Person ' (4' ID 'varchar( +) not NULL,5' NAME 'varchar( -)DEFAULT NULL,6 PRIMARY KEY(' id ')7) ENGINE=InnoDBDEFAULTCHARSET=Gbk
Change engine to INNODB when creating a table
CREATE TABLEPerson (IDVARCHAR( +)PRIMARY KEY, NAMEVARCHAR( -) ) ENGINE=INNODBDEFAULTCHARSET=GBKCREATE TABLECars (IDVARCHAR( +)PRIMARY KEY, NAMEVARCHAR( -), Price NUMERIC (5,2), PIDVARCHAR( +), CONSTRAINTC_fkFOREIGN KEY(PID)REFERENCESPerson (ID)) ENGINE=INNODB CHARSET=GBK;
This will support the foreign key.
A once and for all method:
Modify My.ini, add in [mysqld]
Default-storage-engine=innodb
To modify the MySQL default encoding:
[Mysqld]
Default-character-set = UTF8
[Client]
Default-character-set = UTF8
MySQL does not support primary foreign keys