【发布时间】:2017-08-23 08:23:11
【问题描述】:
我有两个表 - posts 和 parchive 具有相同的结构,并且想要将记录从一个表移动到另一个表。
id 列是主键 - 自动增量。
insert into posts select * from parchive where id...
错误:
未捕获的 PDOException:SQLSTATE[23000]:完整性约束违规:1062 键“PRIMARY”的重复条目“70”...
第二次尝试:
insert into posts select date, title, subtitle, intro, story, img, tags,...
除了id之外的所有内容都被选中。
错误:
未捕获的 PDOException:SQLSTATE[21S01]:插入值列表与列列表不匹配:1136 列计数与值计数不匹配
有什么帮助吗?
【问题讨论】:
-
insert into posts (date, title, subtitle, intro, story, img, tags,...) select date, title, subtitle, intro, story, img, tags,...应该可以正常工作。不过,我想知道为什么您最终会出现重复的唯一索引错误。 You can find the syntax for mysql's INSERT statement here if you want to RTFM -
@JNevill,它有效,也许你应该发表评论作为答案。
-
太棒了!我很高兴它奏效了。我已将其添加为答案并进行了详细说明以使其更具答案。