从腌制数据加载会导致新保存的数据库错误
为了节省移动数据的时间,我腌制了一些模型并将它们转储到文件中。然后我使用相同的模型将它们重新加载到另一个数据库中。保存工作正常,对象保留了它们的旧 ID,这正是我想要的。但是,在保存新对象时,我遇到了 nextval 错误。
由于不太熟悉 postgres,我不知道如何解决这个问题,以便我可以保留旧记录及其现有 ID,同时能够继续添加新数据。
谢谢, 托马斯
In order to save time moving data I pickled some models and dumped them to file. I then reloaded them into another database using the same exact model. The save worked fine and the objects kept their old id which is what I wanted. However, when saving new objects I run into nextval errors.
Not being very adept with postgres, I'm not sure how to fix this so I can keep old records with their existing ID while being able to continue adding new data.
Thanks,
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上有一个 django 命令可以打印出序列重置 SQL,名为 sqlsequencereset。
There is actually a django command that prints out sequence reset SQL called sqlsequencereset.
我认为您正在谈论用于自动递增 id 字段的序列。
这里最简单的解决方案是在“psql”shell中:
并使用此命令中的值:
这应该可以解决问题。
I think that you are talking about the sequence that is being used for autoincrementing your id fields.
the easiest solution here would be in a "psql" shell:
and use the value in this command:
that should do the trick.