问题描述
现在,您需要重命名Django中的模型(或者在最近遇到的一个案例中,将一个模型分成两个,使用新的/不同的名称)。是的,适当的规划有助于避免这种情况,但有时候是现实干预。
Every now and then, you have the need to rename a model in Django (or, in one recent case I encountered, split one model into two, with new/different names). Yes, proper planning helps to avoid this situation, but sometimes reality intervenes.
在重新命名数据库中的相应表并修复受影响的代码后,仍然存在一个问题:授予用户或组对这些模型操作的任何权限仍将引用旧的模型名称。有没有自动或半自动的方式来解决这个问题,还是只是手动分组手术的问题? (在开发中你可以删除auth_permissions表和syncdb来重新创建它,但生产不是那么简单)。
After renaming corresponding tables in the db and fixing affected code, one problem remains: Any permissions granted to Users or Groups to operate on those models still references the old model names. Is there any automated or semi-automated way to fix this, or is it just a matter of manual db surgery? (in development you can drop the auth_permissions table and syncdb to recreate it, but production isn't so simple).
推荐答案
如果您恰好已经使用南方模式迁移来重命名表,转发中的以下行将自动完成:
If you happened to have used a South schema migration to rename the table, the following line in the forward migration would have done this automatically:
db.send_create_signal('appname', ['modelname'])
这篇关于在Django中重命名模型后修复auth_permission表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!