MySQL does not support primary foreign keys

Source: Internet
Author: User

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

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.