A primary must include all columns in the table's partitioning location error?

前端 未结 1 1474
孤街浪徒
孤街浪徒 2021-01-01 18:45

I tried to create a table with range partitioning. But it shows the following error:

A primary must include all columns in the table\'s partitioning

相关标签:
1条回答
  • 2021-01-01 19:16

    You are partitioning data using fldconfirmdate, which is part of your PK, but not a part of your UNIQUE KEY fld_id.

    This is extracted from the MySQL manual:

    In other words, every unique key on the table must use every column in the table's partitioning expression.

    Which means that, making fldconfirmdate to be a part of your UNIQUE KEY 'fld_id´ will solve the problem.

    CREATE TABLE `tbl_emp_confirmation` (
      `fld_id` int(11) NOT NULL AUTO_INCREMENT,
      `fldemp_id` varchar(100) DEFAULT NULL,
      `fldempname` varchar(100) DEFAULT NULL,
      `fldjoindate` varchar(100) DEFAULT NULL,
      `fldconfirmdate` Date NOT NULL,
      `fldresigndate` varchar(100) DEFAULT NULL,
      `fldstatus` varchar(50) DEFAULT NULL,
      `fldcon_status` varchar(100) DEFAULT NULL,
      UNIQUE KEY `fld_id` (`fld_id`, `fldconfirmdate`),
      KEY `in_empconfirmation` (`fldemp_id`,`fldempname`,`fldjoindate`,`fldconfirmdate`)
      ) PARTITION BY RANGE ( Month(fldconfirmdate))
      (PARTITION p_JAN VALUES LESS THAN (TO_DAYS('2011-01-01')),
     PARTITION p_FEB VALUES LESS THAN (TO_DAYS('2011-02-01')),
     PARTITION p_MAR VALUES LESS THAN (TO_DAYS('2011-03-01')),
     PARTITION p_APR VALUES LESS THAN (TO_DAYS('2011-04-01')),
     PARTITION p_MAY VALUES LESS THAN (TO_DAYS('2011-05-01')),
     PARTITION p_MAX VALUES LESS THAN MAXVALUE );
    
    0 讨论(0)
提交回复
热议问题