重构:如何删除模型?
我有一个导致过多复杂性的模型,因此我想消除它,转向一种更简单的做事方式。不过,我不想立即将数据删除在此数据库表中。
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_blocks
将surstert
从未被调用过(要捕获我未能删除的任何代码的任何位),
其次,重命名模型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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论