重构:如何删除模型?

发布于 2025-02-10 01:55:27 字数 599 浏览 0 评论 0原文

我有一个导致过多复杂性的模型,因此我想消除它,转向一种更简单的做事方式。不过,我不想立即将数据删除在此数据库表中。

class PRSblock( models.Model):
    PRS = models.ForeignKey( 'jobs.PRS2', models.CASCADE, related_name='prs_blocks')
    # no other relational fields

因此,首先,将相关名称prs_blocks迁移到opstolete_prs_blocks,然后在prs模型中,添加@property prs_blockssurstert从未被调用过(要捕获我未能删除的任何代码的任何位),

其次,重命名模型prsblock obsolete_prsblock。 IIRC Django Makemigrations会询问我是否重命名,如果我说是的,它将保留数据库表。

这听起来很明智,还是我没有遇到过?

I have a model which is causing too much complexity, and so I want to do away with it and move to a simpler way of doing things. I don't immediately want to scrap the data in this database table, though.

class PRSblock( models.Model):
    PRS = models.ForeignKey( 'jobs.PRS2', models.CASCADE, related_name='prs_blocks')
    # no other relational fields

So, first, migrate the related name prs_blocks to obsolete_prs_blocks and then in the PRS model, add a @property prs_blocks that will assert that it is never called (to trap any bits of code which I failed to remove)

Second, rename the model PRSblock to obsolete_PRSblock. IIRC Django makemigrations will ask whether I renamed it, and if I say yes, it will preserve the database table.

Does this sound sensible or are there any gotchas I haven't though of?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文