views:

31

answers:

1

Hi Guys, 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?

A: 

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']
Ben James
Hi, thanks a lot, I'm now testing your suggestion. I was wondering, is there a way of doing this using manage.py schemamigration --auto? (i.e. just changing the models)
apple_pie