2008-08-11 20:11:25 +08:00
|
|
|
from django.db.backends.creation import BaseDatabaseCreation
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class DatabaseCreation(BaseDatabaseCreation):
|
|
|
|
# This dictionary maps Field objects to their associated MySQL column
|
|
|
|
# types, as strings. Column-type strings can contain format strings; they'll
|
|
|
|
# be interpolated against the values of Field.__dict__ before being output.
|
|
|
|
# If a column type is set to None, it won't be included in the output.
|
|
|
|
data_types = {
|
2013-07-08 08:39:54 +08:00
|
|
|
'AutoField': 'integer AUTO_INCREMENT',
|
|
|
|
'BinaryField': 'longblob',
|
|
|
|
'BooleanField': 'bool',
|
|
|
|
'CharField': 'varchar(%(max_length)s)',
|
2008-08-11 20:11:25 +08:00
|
|
|
'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
|
2013-07-08 08:39:54 +08:00
|
|
|
'DateField': 'date',
|
|
|
|
'DateTimeField': 'datetime',
|
|
|
|
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
|
|
|
'FileField': 'varchar(%(max_length)s)',
|
|
|
|
'FilePathField': 'varchar(%(max_length)s)',
|
|
|
|
'FloatField': 'double precision',
|
|
|
|
'IntegerField': 'integer',
|
|
|
|
'BigIntegerField': 'bigint',
|
|
|
|
'IPAddressField': 'char(15)',
|
2011-06-11 21:48:24 +08:00
|
|
|
'GenericIPAddressField': 'char(39)',
|
2013-07-08 08:39:54 +08:00
|
|
|
'NullBooleanField': 'bool',
|
|
|
|
'OneToOneField': 'integer',
|
2008-08-11 20:11:25 +08:00
|
|
|
'PositiveIntegerField': 'integer UNSIGNED',
|
|
|
|
'PositiveSmallIntegerField': 'smallint UNSIGNED',
|
2013-07-08 08:39:54 +08:00
|
|
|
'SlugField': 'varchar(%(max_length)s)',
|
2008-08-11 20:11:25 +08:00
|
|
|
'SmallIntegerField': 'smallint',
|
2013-07-08 08:39:54 +08:00
|
|
|
'TextField': 'longtext',
|
|
|
|
'TimeField': 'time',
|
2008-08-11 20:11:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def sql_table_creation_suffix(self):
|
|
|
|
suffix = []
|
2009-12-22 23:18:51 +08:00
|
|
|
if self.connection.settings_dict['TEST_CHARSET']:
|
|
|
|
suffix.append('CHARACTER SET %s' % self.connection.settings_dict['TEST_CHARSET'])
|
|
|
|
if self.connection.settings_dict['TEST_COLLATION']:
|
|
|
|
suffix.append('COLLATE %s' % self.connection.settings_dict['TEST_COLLATION'])
|
2008-08-11 20:11:25 +08:00
|
|
|
return ' '.join(suffix)
|
|
|
|
|
2013-01-28 17:17:56 +08:00
|
|
|
def sql_for_inline_foreign_key_references(self, model, field, known_models, style):
|
2008-08-11 20:11:25 +08:00
|
|
|
"All inline references are pending under MySQL"
|
|
|
|
return [], True
|
2013-02-24 00:07:50 +08:00
|
|
|
|
|
|
|
def sql_destroy_indexes_for_fields(self, model, fields, style):
|
|
|
|
if len(fields) == 1 and fields[0].db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(fields[0].db_tablespace)
|
|
|
|
elif model._meta.db_tablespace:
|
|
|
|
tablespace_sql = self.connection.ops.tablespace_sql(model._meta.db_tablespace)
|
|
|
|
else:
|
|
|
|
tablespace_sql = ""
|
|
|
|
if tablespace_sql:
|
|
|
|
tablespace_sql = " " + tablespace_sql
|
|
|
|
|
|
|
|
field_names = []
|
|
|
|
qn = self.connection.ops.quote_name
|
|
|
|
for f in fields:
|
|
|
|
field_names.append(style.SQL_FIELD(qn(f.column)))
|
|
|
|
|
|
|
|
index_name = "%s_%s" % (model._meta.db_table, self._digest([f.name for f in fields]))
|
|
|
|
|
|
|
|
from ..util import truncate_name
|
|
|
|
|
|
|
|
return [
|
|
|
|
style.SQL_KEYWORD("DROP INDEX") + " " +
|
|
|
|
style.SQL_TABLE(qn(truncate_name(index_name, self.connection.ops.max_name_length()))) + " " +
|
|
|
|
style.SQL_KEYWORD("ON") + " " +
|
|
|
|
style.SQL_TABLE(qn(model._meta.db_table)) + ";",
|
|
|
|
]
|