2 from django.db import connection
3 from django.conf import settings
4 from south.db import generic
6 class DatabaseOperations(generic.DatabaseOperations):
9 MySQL implementation of database operations.
12 alter_string_set_type = ''
13 alter_string_set_null = 'MODIFY %(column)s %(type)s NULL;'
14 alter_string_drop_null = 'MODIFY %(column)s %(type)s NOT NULL;'
15 drop_index_string = 'DROP INDEX %(index_name)s ON %(table_name)s'
16 allows_combined_alters = False
17 has_ddl_transactions = False
19 def execute(self, sql, params=[]):
20 if hasattr(settings, "DATABASE_STORAGE_ENGINE") and \
21 settings.DATABASE_STORAGE_ENGINE:
22 generic.DatabaseOperations.execute(self, "SET storage_engine=%s;" %
23 settings.DATABASE_STORAGE_ENGINE)
24 return generic.DatabaseOperations.execute(self, sql, params)
25 execute.__doc__ = generic.DatabaseOperations.execute.__doc__
27 def rename_column(self, table_name, old, new):
28 if old == new or self.dry_run:
31 qn = connection.ops.quote_name
33 rows = [x for x in self.execute('DESCRIBE %s' % (qn(table_name),)) if x[0] == old]
36 raise ValueError("No column '%s' in '%s'." % (old, table_name))
43 rows[0][2] == "YES" and "NULL" or "NOT NULL",
44 rows[0][3] == "PRI" and "PRIMARY KEY" or "",
45 rows[0][4] and "DEFAULT " or "",
46 rows[0][4] and "%s" or "",
50 sql = 'ALTER TABLE %s CHANGE COLUMN %s %s %s %s %s %s %s %s;' % params
53 self.execute(sql, (rows[0][4],))
58 def rename_table(self, old_table_name, table_name):
60 Renames the table 'old_table_name' to 'table_name'.
62 if old_table_name == table_name:
65 qn = connection.ops.quote_name
66 params = (qn(old_table_name), qn(table_name))
67 self.execute('RENAME TABLE %s TO %s;' % params)