mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Refs #25415 -- Made MySQL backend skip field validation of unsupported models.
This commit is contained in:
parent
00c7bfadf4
commit
391c450fba
@ -32,25 +32,33 @@ class DatabaseValidation(BaseDatabaseValidation):
|
||||
No character (varchar) fields can have a length exceeding 255
|
||||
characters if they have a unique index on them.
|
||||
"""
|
||||
from django.db import connection
|
||||
|
||||
errors = super(DatabaseValidation, self).check_field(field, **kwargs)
|
||||
|
||||
# Ignore any related fields.
|
||||
if getattr(field, 'remote_field', None) is None:
|
||||
field_type = field.db_type(connection)
|
||||
if getattr(field, 'remote_field', None):
|
||||
return errors
|
||||
|
||||
# Ignore any non-concrete fields
|
||||
if field_type is None:
|
||||
return errors
|
||||
# Ignore fields with unsupported features.
|
||||
db_supports_all_required_features = all(
|
||||
getattr(self.connection.features, feature, False)
|
||||
for feature in field.model._meta.required_db_features
|
||||
)
|
||||
if not db_supports_all_required_features:
|
||||
return errors
|
||||
|
||||
if (field_type.startswith('varchar') and field.unique and
|
||||
(field.max_length is None or int(field.max_length) > 255)):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
'MySQL does not allow unique CharFields to have a max_length > 255.',
|
||||
obj=field,
|
||||
id='mysql.E001',
|
||||
)
|
||||
field_type = field.db_type(self.connection)
|
||||
|
||||
# Ignore non-concrete fields.
|
||||
if field_type is None:
|
||||
return errors
|
||||
|
||||
if (field_type.startswith('varchar') and field.unique and
|
||||
(field.max_length is None or int(field.max_length) > 255)):
|
||||
errors.append(
|
||||
checks.Error(
|
||||
'MySQL does not allow unique CharFields to have a max_length > 255.',
|
||||
obj=field,
|
||||
id='mysql.E001',
|
||||
)
|
||||
)
|
||||
return errors
|
||||
|
@ -217,7 +217,7 @@ class CharFieldTests(TestCase):
|
||||
field = models.CharField(unique=True, max_length=256)
|
||||
|
||||
field = Model._meta.get_field('field')
|
||||
validator = DatabaseValidation(connection=None)
|
||||
validator = DatabaseValidation(connection=connection)
|
||||
errors = validator.check_field(field)
|
||||
expected = [
|
||||
Error(
|
||||
|
Loading…
Reference in New Issue
Block a user