web/lib/django/db/backends/mysql/creation.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
     1 from django.conf import settings
       
     2 from django.db.backends.creation import BaseDatabaseCreation
     1 from django.db.backends.creation import BaseDatabaseCreation
     3 
     2 
     4 class DatabaseCreation(BaseDatabaseCreation):
     3 class DatabaseCreation(BaseDatabaseCreation):
     5     # This dictionary maps Field objects to their associated MySQL column
     4     # This dictionary maps Field objects to their associated MySQL column
     6     # types, as strings. Column-type strings can contain format strings; they'll
     5     # types, as strings. Column-type strings can contain format strings; they'll
    16         'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
    15         'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
    17         'FileField':         'varchar(%(max_length)s)',
    16         'FileField':         'varchar(%(max_length)s)',
    18         'FilePathField':     'varchar(%(max_length)s)',
    17         'FilePathField':     'varchar(%(max_length)s)',
    19         'FloatField':        'double precision',
    18         'FloatField':        'double precision',
    20         'IntegerField':      'integer',
    19         'IntegerField':      'integer',
       
    20         'BigIntegerField':   'bigint',
    21         'IPAddressField':    'char(15)',
    21         'IPAddressField':    'char(15)',
    22         'NullBooleanField':  'bool',
    22         'NullBooleanField':  'bool',
    23         'OneToOneField':     'integer',
    23         'OneToOneField':     'integer',
    24         'PositiveIntegerField': 'integer UNSIGNED',
    24         'PositiveIntegerField': 'integer UNSIGNED',
    25         'PositiveSmallIntegerField': 'smallint UNSIGNED',
    25         'PositiveSmallIntegerField': 'smallint UNSIGNED',
    29         'TimeField':         'time',
    29         'TimeField':         'time',
    30     }
    30     }
    31 
    31 
    32     def sql_table_creation_suffix(self):
    32     def sql_table_creation_suffix(self):
    33         suffix = []
    33         suffix = []
    34         if settings.TEST_DATABASE_CHARSET:
    34         if self.connection.settings_dict['TEST_CHARSET']:
    35             suffix.append('CHARACTER SET %s' % settings.TEST_DATABASE_CHARSET)
    35             suffix.append('CHARACTER SET %s' % self.connection.settings_dict['TEST_CHARSET'])
    36         if settings.TEST_DATABASE_COLLATION:
    36         if self.connection.settings_dict['TEST_COLLATION']:
    37             suffix.append('COLLATE %s' % settings.TEST_DATABASE_COLLATION)
    37             suffix.append('COLLATE %s' % self.connection.settings_dict['TEST_COLLATION'])
    38         return ' '.join(suffix)
    38         return ' '.join(suffix)
    39 
    39 
    40     def sql_for_inline_foreign_key_references(self, field, known_models, style):
    40     def sql_for_inline_foreign_key_references(self, field, known_models, style):
    41         "All inline references are pending under MySQL"
    41         "All inline references are pending under MySQL"
    42         return [], True
    42         return [], True
    43         
    43 
    44     def sql_for_inline_many_to_many_references(self, model, field, style):
    44     def sql_for_inline_many_to_many_references(self, model, field, style):
    45         from django.db import models
    45         from django.db import models
    46         opts = model._meta
    46         opts = model._meta
    47         qn = self.connection.ops.quote_name
    47         qn = self.connection.ops.quote_name
    48         
    48 
    49         table_output = [
    49         table_output = [
    50             '    %s %s %s,' %
    50             '    %s %s %s,' %
    51                 (style.SQL_FIELD(qn(field.m2m_column_name())),
    51                 (style.SQL_FIELD(qn(field.m2m_column_name())),
    52                 style.SQL_COLTYPE(models.ForeignKey(model).db_type()),
    52                 style.SQL_COLTYPE(models.ForeignKey(model).db_type(connection=self.connection)),
    53                 style.SQL_KEYWORD('NOT NULL')),
    53                 style.SQL_KEYWORD('NOT NULL')),
    54             '    %s %s %s,' %
    54             '    %s %s %s,' %
    55             (style.SQL_FIELD(qn(field.m2m_reverse_name())),
    55             (style.SQL_FIELD(qn(field.m2m_reverse_name())),
    56             style.SQL_COLTYPE(models.ForeignKey(field.rel.to).db_type()),
    56             style.SQL_COLTYPE(models.ForeignKey(field.rel.to).db_type(connection=self.connection)),
    57             style.SQL_KEYWORD('NOT NULL'))
    57             style.SQL_KEYWORD('NOT NULL'))
    58         ]
    58         ]
    59         deferred = [
    59         deferred = [
    60             (field.m2m_db_table(), field.m2m_column_name(), opts.db_table,
    60             (field.m2m_db_table(), field.m2m_column_name(), opts.db_table,
    61                 opts.pk.column),
    61                 opts.pk.column),
    62             (field.m2m_db_table(), field.m2m_reverse_name(),
    62             (field.m2m_db_table(), field.m2m_reverse_name(),
    63                 field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
    63                 field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
    64             ]
    64             ]
    65         return table_output, deferred
    65         return table_output, deferred
    66