diff options
author | Adam Chainz <adam@adamj.eu> | 2016-11-30 21:10:22 +0000 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-12-29 12:01:48 -0500 |
commit | 391c450fbae8c3301954563288147578a1ae4a6d (patch) | |
tree | cc39da331c7285948e0b122ac00866fd7e58623f /django/db/backends/mysql/validation.py | |
parent | 00c7bfadf40996e84344f662b280f92467710eab (diff) | |
download | django-391c450fbae8c3301954563288147578a1ae4a6d.tar.gz |
Refs #25415 -- Made MySQL backend skip field validation of unsupported models.
Diffstat (limited to 'django/db/backends/mysql/validation.py')
-rw-r--r-- | django/db/backends/mysql/validation.py | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py index 5a50663dd2..3492034eba 100644 --- a/django/db/backends/mysql/validation.py +++ b/django/db/backends/mysql/validation.py @@ -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) - - # Ignore any 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', - ) + if getattr(field, 'remote_field', 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 + + 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 |