2 from django.db import connection
3 from south.db import generic
5 class DatabaseOperations(generic.DatabaseOperations):
8 MySQL implementation of database operations.
11 alter_string_set_type = ''
12 alter_string_set_null = 'MODIFY %(column)s %(type)s NULL;'
13 alter_string_drop_null = 'MODIFY %(column)s %(type)s NOT NULL;'
15 def rename_column(self, table_name, old, new):
19 qn = connection.ops.quote_name
21 rows = [x for x in self.execute('DESCRIBE %s' % (qn(table_name),)) if x[0] == old]
24 raise ValueError("No column '%s' in '%s'." % (old, table_name))
32 rows[0][2] == "YES" and "NULL" or "NOT NULL",
33 rows[0][3] == "PRI" and "PRIMARY KEY" or "",
34 rows[0][4] and "DEFAULT %s" % rows[0][4] or "",
38 self.execute('ALTER TABLE %s CHANGE COLUMN %s %s %s;' % params)
41 def rename_table(self, old_table_name, table_name):
43 Renames the table 'old_table_name' to 'table_name'.
45 if old_table_name == table_name:
48 qn = connection.ops.quote_name
49 params = (qn(old_table_name), qn(table_name))
50 self.execute('RENAME TABLE %s TO %s;' % params)