premise
Database table name automatically generated, generated in accordance with APPname + table name, but because the interface needs, table name may not be such a configuration, only the name of the table themselves, can not add a prefix, the records about the modification process and commands.
Django Version: 1.6
Step 1: Generate empty file to record changes
命令:python manage.py schemamigration appname --empty name_of_migration
appname:app的name根据实际情况
name_of_migration:最终生成修改记录文件的名称,可以用这个也可以随便取一个别的,就是0001开头的文件,自动保存在migrations目录下
Step two: modify the generated files
打开第一步生成的文件
修改如下部分内容
class Migration(SchemaMigration):
def forwards(self, orm):
db.rename_table('yourapp_foo', 'yourapp_bar')
def backwards(self, orm):
db.rename_table('yourapp_bar','yourapp_foo')
旧名字:yourapp_foo
新名字:yourapp_bar(这里可以用appname+名字,也可以直接写名字)
The third step: Synchronize Database
python manage.py migrate appname