ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

When you create a partition table, mysql report such a mistake.

ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function

The effect that the column must be used to make the partition table is the primary key in the primary key or a .

After processing the like understand why, for the partitioned column is also added to the primary key in the primary key to form a composite, and then executed.

CREATE TABLE `f_res` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `eid` int(10) unsigned NOT NULL DEFAULT '0',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`,`eid`),
  KEY `idx_eid` (`eid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 partition by hash(eid) partitions 10;

So that it can perform successful.

Note : When doing the partition table, according to the choice of the partition field to be careful, you need to consider carefully the field at hand as the partitioning is appropriate, this field is added to the primary key as the composite primary key is appropriate.

Published 105 original articles · won praise 58 · views 410 000 +

Guess you like

Origin blog.csdn.net/ljl890705/article/details/78490819