Search code examples
pythondjangodjango-south

Changing the encoding of a table with django+south migrations


Django and south newbie here

I need to change the encoding of a table I created, does anyone know a way to do so using a migration?


Solution

  • I think the solution will be database-specific. For example, for a MySQL database:

    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']