def check_field(self, field, **kwargs): """ MySQL has the following field length restriction: No character (varchar) fields can have a length exceeding 255 characters if they have a unique index on them. """ from arouse._dj.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', )) return errors
def check(self, **kwargs): errors = super(ArrayField, self).check(**kwargs) if self.base_field.remote_field: errors.append( checks.Error('Base field for array cannot be a related field.', obj=self, id='postgres.E002')) else: # Remove the field name checks as they are not needed here. base_errors = self.base_field.check() if base_errors: messages = '\n '.join('%s (%s)' % (error.msg, error.id) for error in base_errors) errors.append( checks.Error('Base field for array has errors:\n %s' % messages, obj=self, id='postgres.E001')) return errors
def _check_primary_key(self): if self._primary_key_set_explicitly: return [ checks.Error( "'primary_key' is not a valid argument for a %s." % self.__class__.__name__, obj=self, id='fields.E201', ) ] else: return []
def _check_unique(self): if self._unique_set_explicitly: return [ checks.Error( "'unique' is not a valid argument for a %s." % self.__class__.__name__, obj=self, id='fields.E200', ) ] else: return []
def _check_image_library_installed(self): try: from PIL import Image # NOQA except ImportError: return [ checks.Error( 'Cannot use ImageField because Pillow is not installed.', hint=('Get Pillow at https://pypi.python.org/pypi/Pillow ' 'or run command "pip install Pillow".'), obj=self, id='fields.E210', ) ] else: return []