在 Django 部署中维护内容类型 pk 完整性

发布于 2024-08-29 03:11:42 字数 131 浏览 1 评论 0原文

当您在 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 技术交流群。

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

发布评论

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

评论(2

穿越时光隧道 2024-09-05 03:11:42

运行 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.

一口甜 2024-09-05 03:11:42

这个问题在 Django 1.2(应该在两周内发布)中通过 自然键。

The problem is solved in Django 1.2 (which is supposed to come out in two weeks) with natural keys.

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