ALTER TABLE causes auto_increment resulting key 'PRIMARY'
修改表为主键的自动增长值时,报出以下错误:
mysql> ALTER TABLE YOON CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT ADD PRIMARY KEY (id);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD PRIMARY KEY (id)' at line 1
解决:
将ID值为0的那条记录或其他大于0且不重复的数据;
查询重复数据:
mysql> select id,count(*) as count from yoon group by id having count > 1;
+------+-------+
| id | count |
+------+-------+
| 1 | 2 |
+------+-------+
1 row in set (0.00 sec)
mysql> select * from yoon where id =1;
+------+------+
| id | name |
+------+------+
| 1 | AAAA |
| 1 | DDDD |
+------+------+
2 rows in set (0.00 sec)
mysql> delete from yoon where name='DDDD';
Query OK, 1 row affected (0.00 sec)
添加表为主键的自动增长值时,依旧报出以下错误:
mysql> ALTER TABLE YOON CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT ADD PRIMARY KEY (id);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD PRIMARY KEY (id)' at line 1
原因:
很多人都忽略了NULL值:
mysql> select * from yoon where id is null;
+------+------+
| id | name |
+------+------+
| NULL | EEEE |
+------+------+
1 row in set (0.00 sec)
mysql> delete from yoon where id is null;
Query OK, 1 row affected (0.01 sec)
mysql> alter table yoon change column id id int(11) not null auto_increment,add primary key(id);
Query OK, 3 rows affected (0.04 sec)
Records: 3 Duplicates: 0 Warnings: 0
or
alter table yoon modify id int(11) not null auto_increment primary key;
ALTER TABLE causes auto_increment resulting key 'PRIMARY'的更多相关文章
- ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry ’1′ for key
当我用SQLyog尝试修改已有记录的mysql数据表的主键为自动增长时,报出以下错误 ALTER TABLE causes auto_increment resequencing, resulting ...
- mysql ERROR 1062: ALTER TABLE causes auto_increment resequen
当我用Navicat尝试修改已有记录的mysql数据表的主键为自动增长时,报出以下错误 1602 ALTER TABLE causes auto_increment resequencing, res ...
- sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1091, "Can't DROP 'users_ibfk_1'; check that column/key exists") [SQL: ALTER TABLE users DROP FOREIGN KEY users_ibfk_1]
flask 迁移数据库报错 报错: sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1091, "Can't DROP ...
- ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry ’1′ for key ‘PRIMARY’
在打开navicat设计表时,想更改主键id为自动增长,会弹出来这么一个提示.翻译为:更改表将导致自动增长(列)的重新排序,主键会有重复的‘1’.原因是因为auto_increment是从1开始自增的 ...
- ALTER TABLE 语句与 FOREIGN KEY 约束"FK_SCHEDULE_REFERENCE_POSTCONF"冲突。
主要原因是因为两个表中有数据不匹配,只要把不匹配的数据删掉就行了.
- code first 添加外键时,与原有的数据冲突ALTER TABLE 语句与 FOREIGN KEY 约束"FK_XXXXX"冲突
问题的原因是新增的外键字段没有默认值,造成的,有很多方法可以解决,我这里通过修改生成的迁移文件,设定为可空,或者设置默认值即可.具体看情况使用.
- resulting in duplicate entry '1' for key 'primary'
现在有一个标签表,里面已经填入了一些数据了,想把主键生成策略改成自增的: ALTER TABLE `tags` CHANGE COLUMN `Id` `Id` INT(11) NOT NULL AUT ...
- 翻译:MariaDB ALTER TABLE语句
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
- alter table,复制, 单表查询
修改表 语法:1. 修改表名 ALTER TABLE 表名 RENAME 新表名; 2. 增加字段 ALTER TABLE 表名 ...
随机推荐
- Ubuntu/Debian 安装lxml的正确方式
lxml是Python的一个库,主要用于处理XML和HTML. 最近需要用lxml,但是在Ubuntu上直接pip安装失败,研究了半天终于找到了正确安装方法,记录在此. 由于Ubuntu和Debian ...
- 瀑布流插件(jquery.masonry.js)
什么是瀑布流?去看看Pinterest(这才是鼻祖),Mark之,蘑菇街,点点网,还有腾讯的微博广场吧.随着页面滚动条向下滚动,还会不断加载数据块并附加至当前尾部. Masonry是一款很好用的jqu ...
- C#中XML与对象之间的序列化、反序列化
直接上代码: using System; using System.IO; using System.Text; using System.Xml; using System.Xml.Serializ ...
- codeforces 676A A. Nicholas and Permutation(水题)
题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes i ...
- MySQL选择数据库use与mysql_select_db使用详解
在mysql中如果我们在命令模式下选择与切换数据库直接使用use即可,在php中选择数据使用mysql_select_db即可,下面我来介绍一下. 从命令提示符,选择MySQL数据库: 这 ...
- Linux下DNS服务器的基本搭建
技术交流群:286866978 安装与配置 1. 装载光驱 2. 卸载光驱 3. 将安装包放在合适的文件夹并解压(有的更换光盘需要重新装载) 4. 安装 5. 重定向配置文件 6. 配置named.c ...
- BeanDefinition的Resource定位
1.以编程的方式使用DefaultListableBeanFactory时,首先定义一个Resource来定位容器使用的BeanDefiniton.这时使用的是ClassPathResource,这意 ...
- 编程Tips
三元运算符 Vb中的iif(expr,truepart,falsepart)和C#中的expr?truepart:falsepart. 无论expr的结果是true还是false,true/false ...
- 7款震撼人心的HTML5文字特效
1.CSS3五彩文字特效 文字带阴影效果 这是一款非常具有卡通形象的CSS3五彩文字特效,虽然没有迷人的动画效果,但是五彩缤纷的文字展现在屏幕上也是非常酷的,再加上每一个文字都有不同角度的阴影效果,加 ...
- Spring Security (Acegi)的登陆配置
简短记录一下: 在authenticationProcessingFilter这个bean中,如果没有配置<property name="alwaysUseDefaultTargetU ...