您可以使用
db.rename_column功能。
class Migration:
def forwards(self, orm):
# Rename 'name' field to 'full_name'
db.rename_column('app_foo', 'name', 'full_name')
def backwards(self, orm):
# Rename 'full_name' field to 'name'
db.rename_column('app_foo', 'full_name', 'name')
db.rename_column的第一个参数是表名,因此重要的是要记住Django creates table names:
Django automatically derives the name of the database table from the name of your model class and the app that contains it. A model’s database table name is constructed by joining the model’s “app label” — the name you used in manage.py startapp — to the model’s class name, with an underscore between them.
如果你有一个多字,骆驼模型名称,如ProjectItem,表名称将是app_projectitem(即,下划线不会插入项目和项目之间,即使他们是骆驼)。