creation.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from django.db.backends.base.creation import BaseDatabaseCreation
  2. class DatabaseCreation(BaseDatabaseCreation):
  3. def sql_table_creation_suffix(self):
  4. suffix = []
  5. test_settings = self.connection.settings_dict['TEST']
  6. if test_settings['CHARSET']:
  7. suffix.append('CHARACTER SET %s' % test_settings['CHARSET'])
  8. if test_settings['COLLATION']:
  9. suffix.append('COLLATE %s' % test_settings['COLLATION'])
  10. return ' '.join(suffix)
  11. def sql_for_inline_foreign_key_references(self, model, field, known_models, style):
  12. "All inline references are pending under MySQL"
  13. return [], True
  14. def sql_destroy_indexes_for_fields(self, model, fields, style):
  15. if len(fields) == 1 and fields[0].db_tablespace:
  16. tablespace_sql = self.connection.ops.tablespace_sql(fields[0].db_tablespace)
  17. elif model._meta.db_tablespace:
  18. tablespace_sql = self.connection.ops.tablespace_sql(model._meta.db_tablespace)
  19. else:
  20. tablespace_sql = ""
  21. if tablespace_sql:
  22. tablespace_sql = " " + tablespace_sql
  23. field_names = []
  24. qn = self.connection.ops.quote_name
  25. for f in fields:
  26. field_names.append(style.SQL_FIELD(qn(f.column)))
  27. index_name = "%s_%s" % (model._meta.db_table, self._digest([f.name for f in fields]))
  28. from ..utils import truncate_name
  29. return [
  30. style.SQL_KEYWORD("DROP INDEX") + " " +
  31. style.SQL_TABLE(qn(truncate_name(index_name, self.connection.ops.max_name_length()))) + " " +
  32. style.SQL_KEYWORD("ON") + " " +
  33. style.SQL_TABLE(qn(model._meta.db_table)) + ";",
  34. ]