2012-08-18 19:29:31 +08:00
|
|
|
from django.db.backends.schema import BaseDatabaseSchemaEditor
|
|
|
|
|
|
|
|
|
|
|
|
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
|
|
|
|
|
|
|
sql_rename_table = "RENAME TABLE %(old_table)s TO %(new_table)s"
|
|
|
|
|
|
|
|
sql_alter_column_null = "MODIFY %(column)s %(type)s NULL"
|
2012-09-24 19:52:43 +08:00
|
|
|
sql_alter_column_not_null = "MODIFY %(column)s %(type)s NOT NULL"
|
2012-08-18 20:48:54 +08:00
|
|
|
sql_alter_column_type = "MODIFY %(column)s %(type)s"
|
|
|
|
sql_rename_column = "ALTER TABLE %(table)s CHANGE %(old_column)s %(new_column)s %(type)s"
|
2012-08-18 19:29:31 +08:00
|
|
|
|
|
|
|
sql_delete_unique = "ALTER TABLE %(table)s DROP INDEX %(name)s"
|
|
|
|
|
|
|
|
sql_create_fk = "ALTER TABLE %(table)s ADD CONSTRAINT %(name)s FOREIGN KEY (%(column)s) REFERENCES %(to_table)s (%(to_column)s)"
|
|
|
|
sql_delete_fk = "ALTER TABLE %(table)s DROP FOREIGN KEY %(name)s"
|
|
|
|
|
2012-08-31 06:11:56 +08:00
|
|
|
sql_delete_index = "DROP INDEX %(name)s ON %(table)s"
|
2012-08-18 19:29:31 +08:00
|
|
|
|
|
|
|
sql_delete_pk = "ALTER TABLE %(table)s DROP PRIMARY KEY"
|
|
|
|
|
|
|
|
alter_string_set_null = 'MODIFY %(column)s %(type)s NULL;'
|
|
|
|
alter_string_drop_null = 'MODIFY %(column)s %(type)s NOT NULL;'
|
2012-09-05 00:53:31 +08:00
|
|
|
|
|
|
|
sql_create_pk = "ALTER TABLE %(table)s ADD CONSTRAINT %(name)s PRIMARY KEY (%(columns)s)"
|
|
|
|
sql_delete_pk = "ALTER TABLE %(table)s DROP PRIMARY KEY"
|
2014-02-09 20:41:55 +08:00
|
|
|
|
|
|
|
def quote_value(self, value):
|
|
|
|
# Inner import to allow module to fail to load gracefully
|
|
|
|
import MySQLdb.converters
|
|
|
|
return MySQLdb.escape(value, MySQLdb.converters.conversions)
|