简体   繁体   English

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

[英]Changing the encoding of a table with django+south migrations

Django and south newbie here Django和南方新手在这里

I need to change the encoding of a table I created, does anyone know a way to do so using a migration? 我需要更改我创建的表的编码,是否有人知道使用迁移的方法?

I think the solution will be database-specific. 我认为解决方案将是特定于数据库的。 For example, for a MySQL database: 例如,对于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']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM