gpt4 book ai didi

php - 将记录从一个表移动到另一个表

转载 作者:行者123 更新时间:2023-11-28 23:17:46 25 4
gpt4 key购买 nike

我有两个表 - postsparchive 具有相同的结构,我想将记录从一个表移动到另一个表。

id 列是主键 - 自动增量。

insert into posts select * from parchive where id...

错误:

Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '70' for key 'PRIMARY'...

第二次尝试:

insert into posts select date, title, subtitle, intro, story, img, tags,...

除了 id 之外的所有内容都被选中。

错误:

Uncaught PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count

有什么帮助吗?

最佳答案

来 self 上面的评论。如果您只打算将数据插入特定字段,那么您必须在表后指定这些字段:

insert into posts (date, title, subtitle, intro, story, img, tags,...) select date, title, subtitle, intro, story, img, tags,... 

我认为可能值得探讨为什么在插入 ID 时会出现重复的唯一键错误。如果您的 ID 是在您的主表中自动生成的,那么不在您的存档表中自动生成以便 ID 匹配是有意义的。

关于php - 将记录从一个表移动到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43100428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com