Corrected problem with MySQL checks handler and related fields.
This commit is contained in:
parent
151dae2bea
commit
494b408041
|
@ -12,23 +12,21 @@ class DatabaseValidation(BaseDatabaseValidation):
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
errors = super(DatabaseValidation, self).check_field(field, **kwargs)
|
errors = super(DatabaseValidation, self).check_field(field, **kwargs)
|
||||||
try:
|
|
||||||
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
|
# Ignore any related fields.
|
||||||
and (field.max_length is None or int(field.max_length) > 255)):
|
if getattr(field, 'rel', None) is None:
|
||||||
errors.append(
|
field_type = field.db_type(connection)
|
||||||
checks.Error(
|
|
||||||
('Under mysql backend, the field cannot have a "max_length" '
|
if (field_type.startswith('varchar') # Look for CharFields...
|
||||||
'greated than 255 when it is unique.'),
|
and field.unique # ... that are unique
|
||||||
hint=None,
|
and (field.max_length is None or int(field.max_length) > 255)):
|
||||||
obj=field,
|
errors.append(
|
||||||
id='E047',
|
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
|
return errors
|
||||||
|
|
Loading…
Reference in New Issue