Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 235
apple_pie Avatar asked Aug 04 '10 10:08

apple_pie


1 Answers

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']
like image 87
Ben James Avatar answered Sep 19 '22 02:09

Ben James