summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/validation.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2014-01-21 18:37:49 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2014-01-21 18:37:49 +0800
commit494b408041c59e9079e624040d48412559f241ae (patch)
tree351f6b4b31b051fd67c70ba52bb987ae0af09feb /django/db/backends/mysql/validation.py
parent151dae2bea1dad9fa8f24ea8adcf58dbb1820aa8 (diff)
downloaddjango-494b408041c59e9079e624040d48412559f241ae.tar.gz
Corrected problem with MySQL checks handler and related fields.
Diffstat (limited to 'django/db/backends/mysql/validation.py')
-rw-r--r--django/db/backends/mysql/validation.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py
index cc8a7ac75b..4ee701583a 100644
--- a/django/db/backends/mysql/validation.py
+++ b/django/db/backends/mysql/validation.py
@@ -12,23 +12,21 @@ class DatabaseValidation(BaseDatabaseValidation):
from django.db import connection
errors = super(DatabaseValidation, self).check_field(field, **kwargs)
- try:
+
+ # Ignore any related fields.
+ if getattr(field, 'rel', None) is None:
field_type = field.db_type(connection)
- except AttributeError:
- # If the field is a relative field and the target model is
- # missing, then field.rel.to is not a model and doesn't have
- # `_meta` attribute.
- field_type = ''
- if (field_type.startswith('varchar') and field.unique
- and (field.max_length is None or int(field.max_length) > 255)):
- errors.append(
- checks.Error(
- ('Under mysql backend, the field cannot have a "max_length" '
- 'greated than 255 when it is unique.'),
- hint=None,
- obj=field,
- id='E047',
+ if (field_type.startswith('varchar') # Look for CharFields...
+ and field.unique # ... that are unique
+ and (field.max_length is None or int(field.max_length) > 255)):
+ errors.append(
+ checks.Error(
+ ('Under mysql backend, the field cannot have a "max_length" '
+ 'greated than 255 when it is unique.'),
+ hint=None,
+ obj=field,
+ id='E047',
+ )
)
- )
return errors