标签:info inno unsigned src 问题 current created null com
表SQL:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_group_id` tinyint(3) unsigned NOT NULL DEFAULT ‘2‘,
`username` varchar(50) NOT NULL,
`email` varchar(80) NOT NULL,
`password` varchar(50) NOT NULL,
`first_name` varchar(25) DEFAULT NULL,
`last_name` varchar(25) DEFAULT NULL,
`gender` enum(‘m‘,‘f‘,‘u‘) NOT NULL DEFAULT ‘u‘ COMMENT ‘m=>Male, f=>Female, u=>Unspecified‘,
`profile_image` varchar(255) DEFAULT NULL,
`reset_key` varchar(50) DEFAULT NULL,
`block` enum(‘y‘,‘n‘) NOT NULL DEFAULT ‘n‘ COMMENT ‘y=>blocked, n=>notblocked‘,
`created` datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00‘,
`modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=1 ;
对该表进行分区的SQL:
ALTER TABLE users PARTITION BY RANGE(id) (
PARTITION p0 VALUES LESS THAN (200000),
PARTITION p1 VALUES LESS THAN (400000),
PARTITION p2 VALUES LESS THAN (600000),
PARTITION p3 VALUES LESS THAN (800000),
PARTITION p4 VALUES LESS THAN (1000000),
PARTITION p5 VALUES LESS THAN (1200000),
PARTITION p6 VALUES LESS THAN (1400000),
PARTITION p7 VALUES LESS THAN (1600000),
PARTITION p8 VALUES LESS THAN (1800000),
PARTITION p9 VALUES LESS THAN (2000000)
);
错误信息:
原因:
分区表的分区表达式中使用的所有列必须是表可能具有的每个唯一键的一部分。
解决:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_group_id` tinyint(3) unsigned NOT NULL DEFAULT ‘2‘,
`username` varchar(50) NOT NULL,
`email` varchar(80) NOT NULL,
`password` varchar(50) NOT NULL,
`first_name` varchar(25) DEFAULT NULL,
`last_name` varchar(25) DEFAULT NULL,
`gender` enum(‘m‘,‘f‘,‘u‘) NOT NULL DEFAULT ‘u‘ COMMENT ‘m=>Male, f=>Female, u=>Unspecified‘,
`profile_image` varchar(255) DEFAULT NULL,
`reset_key` varchar(50) DEFAULT NULL,
`modify_username` enum(‘0‘,‘1‘) DEFAULT ‘0‘,
`block` enum(‘y‘,‘n‘) NOT NULL DEFAULT ‘n‘ COMMENT ‘y=>blocked, n=>notblocked‘,
`status` enum(‘0‘,‘1‘) DEFAULT ‘0‘,
`created` datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00‘,
`modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `id_username_email` (`id`,`username`,`email`),
KEY `username` (`username`)
KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC
解答:将自增key的id字段添加进unique key,就可以正确运行,也不用担心加入唯一约束会对其以后运行出现问题。
标签:info inno unsigned src 问题 current created null com
原文地址:https://www.cnblogs.com/chenloveslife/p/9464325.html