使用django+south迁移更改表的编码
我是Django和South的新手
我需要更改我创建的一个表的编码,有人知道怎么通过迁移来做到这一点吗?
1 个回答
8
我觉得解决方案会根据不同的数据库而有所不同。比如说,对于MySQL数据库:
from south.db import db
from south.v2 import SchemaMigration
class Migration(SchemaMigration):
def forwards(self, orm):
db.execute('alter table appname_modelname charset=utf8')
db.execute('alter table appname_modelname alter column fieldname charset=utf8')
# et cetera for any other char or text columns
def backwards(self, orm):
db.execute('alter table appname_modelname charset=latin1')
db.execute('alter table appname_modelname alter column fieldname charset=latin1')
# et cetera for any other char or text columns
complete_apps = ['appname']