DB 导入后无法创建节点(重复条目)

发布于 2024-09-30 14:31:30 字数 708 浏览 0 评论 0原文

我导出了一堆表并在它们前面加上“ch_”前缀,然后再次导入它们。全部使用 phpmyadmin。一切都很好......直到我想创造一些东西。它失败并显示以下消息:

user warning: Duplicate entry '4-4' for key 'PRIMARY' query: INSERT INTO ch_node (nid, vid, title, type, uid, status, created, changed, comment, promote, sticky) VALUES (4, 4, 'Nützliche Dokumente', 'page', 1, 1, 1288790996, 1288791130, 0, 0, 0) in /var/www/clients/client20/site60/docroot/includes/database.mysql.inc on line 172.

而每次我尝试保存时“4-4”都会递增。这让我认为数据库中的 auto_increment 值在某种程度上是错误的 - 尽管它在我的 export.sql 中被正确指定。因此,我尝试使用 ALTER TABLE some_table AUTO_INCRMENT=10000 将 auto_increment 值重置为一些荒谬的高数字。仍然是同样的行为......

有人知道这里发生了什么吗?

我之前做过几次这个程序……但没有发生这种情况。这让我发疯:/

i exported a bunch of tables and prefixed them with "ch_" and imported them again. All using phpmyadmin. It all works fine… until I want to create something. It fails with this message:

user warning: Duplicate entry '4-4' for key 'PRIMARY' query: INSERT INTO ch_node (nid, vid, title, type, uid, status, created, changed, comment, promote, sticky) VALUES (4, 4, 'Nützliche Dokumente', 'page', 1, 1, 1288790996, 1288791130, 0, 0, 0) in /var/www/clients/client20/site60/docroot/includes/database.mysql.inc on line 172.

Whereas the '4-4' increments each time i try to save. That made me think the auto_increment value in the DB is somehow wrong - though it was correctly specified in my export.sql. Hence I tried to reset the auto_increment value to some ridiculous high number using ALTER TABLE some_table AUTO_INCREMENT=10000. Still same behaviour…

Anyone an idea what's going on here?

I did this procedure a few times before … but without this happening. It's driving me nuts :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔姬 2024-10-07 14:31:30

那么,您的导入工作正常,只有当您在导入所有内容后尝试插入新记录时,才会出现此错误?如果是这种情况,则可能是:

  1. 您的 auto_increment 设置不正确。
  2. 您正在为 auto_increment 字段指定一个值。

从上面的帖子来看,您似乎正在为 auto_increment 字段指定一个值。您应该将 auto_increment 更新为表的 MAX+1,然后在插入时,不要为该字段指定值,MySQL 将为您使用 auto_increment...

So, your import works fine, it's only when you try to insert a new record after everything has been imported that you get this error? If that's the case, then either:

  1. Your auto_increment isn't set correctly.
  2. You are specifying a value for your auto_increment field.

From the post above, it looks like you're specifying a value for your auto_increment field. You should update your auto_increment to the MAX+1 of your table, and then when you do you're insert, don't specify a value for that field and MySQL will use the auto_increment for you...

雪若未夕 2024-10-07 14:31:30

经验教训:

Drupal 不使用 MySQL 的 auto_increment 值。

据我所知,自动增量不是 SQL Ansi 标准的一部分 - 它只是一个非常常见的事情。 Drupal 不想依赖于不同 RDBMS 的某些实现,因此它们有一个表 {sequences},其中有一列用于表名称和下一个 id 值,可以使用 db_next_id($name)。当然,通过为表名添加前缀,我还必须在序列表中添加前缀。

尽管它一开始就让我抓狂,但我认为这是 drupal 开发人员做出的明智决定。

Lesson learned:

Drupal does not use MySQL's auto_increment value.

As I learned auto increment is not part of the SQL Ansi standard - it's just a very common thing. Drupal does not want to rely on some implementations of different RDBMS, so they have a table {sequences} that has a column for the table name and the next id-value that can be loaded with db_next_id($name). Of course by prefixing the table names, I had to add the prefix in the sequences table as well.

As much as it drove me nuts in the first place, I think it's a wise decision the drupal-developers made.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文