使用django + south迁移更改表的编码

app*_*pie 6 python django django-south

Django和南方新手在这里

我需要更改我创建的表的编码,是否有人知道使用迁移的方法?

Ben*_*mes 7

我认为解决方案将是特定于数据库的.例如,对于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']
Run Code Online (Sandbox Code Playgroud)

  • 你好,非常感谢,我现在正在测试你的建议。我想知道,有没有办法使用 manage.py schemamigration --auto 来做到这一点?(即只是改变模型) (2认同)