在 Django 部署中维护内容类型 pk 完整性
当您在 Django 中运行syncdb时,将重新计算内容类型的主键。如果我创建新模型,下次运行syncdb时,内容类型的主键将会不同。
如果我有一个在生产中运行的应用程序,如何使用新模型更新数据库并保持内容类型 pks 的完整性?
When you run syncdb in Django, the primary keys of the content types will be recomputed. If I create new models, the next time I run syncdb, the primary keys of the content types will be different.
If I have an application running in production, how can I update the database with the new models and keep the integrity of content type pks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行
syncdb
不会更新现有的 ContentType 值 - 这些值存储在数据库中并且不会更改。因此依赖他们的关系不会受到影响。然而,当您运行syncdb时,新定义的模型将获得新的ContentType值,并且当前无法提前定义这些值。正如 Ludwik 指出的,这个问题在 1.2 中得到了解决。
Running
syncdb
doesn't update existing ContentType values - these are stored in the database and aren't changed. So relations that depend on them won't be affected.Newly defined models will however get new ContentType values when you run syncdb, and there's currently no way of defining in advance what those will be. As Ludwik points out, this issue is solved in 1.2.
这个问题在 Django 1.2(应该在两周内发布)中通过 自然键。
The problem is solved in Django 1.2 (which is supposed to come out in two weeks) with natural keys.