diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index 0d83ef5..065b4d2 100644
a
|
b
|
class FileField(Field):
|
230 | 230 | |
231 | 231 | def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs): |
232 | 232 | self._primary_key_set_explicitly = 'primary_key' in kwargs |
233 | | self._unique_set_explicitly = 'unique' in kwargs |
234 | 233 | |
235 | 234 | self.storage = storage or default_storage |
236 | 235 | self.upload_to = upload_to |
… |
… |
class FileField(Field):
|
240 | 239 | |
241 | 240 | def check(self, **kwargs): |
242 | 241 | errors = super(FileField, self).check(**kwargs) |
243 | | errors.extend(self._check_unique()) |
244 | 242 | errors.extend(self._check_primary_key()) |
245 | 243 | return errors |
246 | 244 | |
247 | | def _check_unique(self): |
248 | | if self._unique_set_explicitly: |
249 | | return [ |
250 | | checks.Error( |
251 | | "'unique' is not a valid argument for a %s." % self.__class__.__name__, |
252 | | obj=self, |
253 | | id='fields.E200', |
254 | | ) |
255 | | ] |
256 | | else: |
257 | | return [] |
258 | | |
259 | 245 | def _check_primary_key(self): |
260 | 246 | if self._primary_key_set_explicitly: |
261 | 247 | return [ |
diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
index a38cd1e..097bf3e 100644
a
|
b
|
File Fields
|
183 | 183 | ~~~~~~~~~~~ |
184 | 184 | |
185 | 185 | * **fields.E200**: ``unique`` is not a valid argument for a ``FileField``. |
| 186 | *This check is removed in Django 1.11*. |
186 | 187 | * **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``. |
187 | 188 | * **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed. |
188 | 189 | |
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 873310b..96d9906 100644
a
|
b
|
field, a :exc:`django.db.IntegrityError` will be raised by the model's
|
307 | 307 | :meth:`~django.db.models.Model.save` method. |
308 | 308 | |
309 | 309 | This option is valid on all field types except :class:`ManyToManyField`, |
310 | | :class:`OneToOneField`, and :class:`FileField`. |
| 310 | and :class:`OneToOneField` |
311 | 311 | |
312 | 312 | Note that when ``unique`` is ``True``, you don't need to specify |
313 | 313 | :attr:`~Field.db_index`, because ``unique`` implies the creation of an index. |
314 | 314 | |
| 315 | .. versionchanged:: 1.11 |
| 316 | |
| 317 | In older versions, ``unique=True`` can't be used on :class:`FileField`. |
| 318 | |
315 | 319 | ``unique_for_date`` |
316 | 320 | ------------------- |
317 | 321 | |
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py
index 2f16e83..aff6a74 100644
a
|
b
|
class FileFieldTests(SimpleTestCase):
|
440 | 440 | expected = [] |
441 | 441 | self.assertEqual(errors, expected) |
442 | 442 | |
443 | | def test_unique(self): |
444 | | class Model(models.Model): |
445 | | field = models.FileField(unique=False, upload_to='somewhere') |
446 | | |
447 | | field = Model._meta.get_field('field') |
448 | | errors = field.check() |
449 | | expected = [ |
450 | | Error( |
451 | | "'unique' is not a valid argument for a FileField.", |
452 | | obj=field, |
453 | | id='fields.E200', |
454 | | ) |
455 | | ] |
456 | | self.assertEqual(errors, expected) |
457 | | |
458 | 443 | def test_primary_key(self): |
459 | 444 | class Model(models.Model): |
460 | 445 | field = models.FileField(primary_key=False, upload_to='somewhere') |