将一个 Django 应用程序迁移到另一个应用程序的最佳方法是什么

发布于 2025-01-04 07:02:48 字数 176 浏览 4 评论 0原文

我正在开发一个 Django 项目,我必须使用 South 将一个应用程序迁移到另一个应用程序。我有旧的内部消息应用程序,我必须将其替换为另一个完全不同的应用程序。我想知道是否可以通过 orm,但旧应用程序在 INSTALLED_APPS 中不再存在,所以没有意义。使用 SQL 过程可以做到这一点吗?我当时想保持应用程序数据库类型独立。

I am working on a Django project where I have to use South to migrate one application to another. I have the old internal message application which I have to replace by another completely different. I was wondering if I could pass by orm, but the old application doesn't exist anymore in the INSTALLED_APPS, so no sense. Does using a SQL procedure is the way to do that? I'd like to keep the application DB type independant at the time.

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

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

发布评论

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

评论(2

沫离伤花 2025-01-11 07:02:48

Django 应用程序在数据库中命名,因此您应该能够临时安装这两个应用程序。我将其分解为大约三个迁移:

  1. 用于添加新应用程序的架构迁移。如果其他应用程序需要与新应用程序具有外键关系,请添加这些关系并确保它们全部可为空。
  2. 数据迁移,用于遍历旧应用程序中的模型对象并在新应用程序中创建等效的对象。
  3. 用于删除旧应用程序的架构迁移。

Django applications are namespaced in the database so you ought to be able to temporarily have both applications installed. I would break it down to about three migrations:

  1. A schemamigration to add the new application. If other applications need to have foreign key relations to the new application, add those and just make sure they are all nullable.
  2. A datamigration to walk the model objects in the old application and create the equivalent ones in the new application.
  3. A schemamigration to remove the old application.
醉殇 2025-01-11 07:02:48
  1. schemamigration:python manage.py schemamigration myapp(具有可为空的外键)

  2. datamigration:Django 自定义 sql 是我的朋友 -> https://docs.djangoproject.com/en/dev/topics/db/ sql/
    制作了我的自定义数据迁移脚本,使项目数据库保持独立

  3. 使用2删除旧的应用程序架构。

  4. (可选)向后救援脚本

  1. schemamigration: python manage.py schemamigration myapp (with nullable foreign keys)

  2. datamigration: Django custom sql is my friend -> https://docs.djangoproject.com/en/dev/topics/db/sql/
    have made my custom data migration script keeping the project DB independent

  3. remove the old application schema using 2.

  4. (optional) a backwards rescue script

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