Changes between Initial Version and Version 1 of Ticket #10244, comment 19
- Timestamp:
- Jun 2, 2022, 9:51:03 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #10244, comment 19
initial v1 18 18 - `FileField(null=True, unique=True)` is broken, because the database entry is `''` instead of `null`, so we get a unique-constraint violation if we try to create another instance with `None` 19 19 20 The latter is basically what is described in the [https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.Field.null model field reference] (my emphasis):20 The latter is basically what is described in the [https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.Field.null model field reference]: 21 21 22 > ... One exception is when a `CharField` has both `unique=True` and `blank=True` set. In this situation, `null=True` is *required to avoid unique constraint violations when saving multiple objects with blank values*.22 > ... One exception is when a `CharField` has both `unique=True` and `blank=True` set. In this situation, `null=True` is required to avoid unique constraint violations when saving multiple objects with blank values. 23 23 24 24 So, currently, we cannot make a `FileField` unique and optional at the same time. … … 26 26 Why not just bite the bullet and make a backward incompatible change, for the sake of consistency? 27 27 28 29 [1]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.FileField.storage30 [2]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#filefield31 [3]: https://stackoverflow.com/q/885041532 [4]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.Field.null33 [5]: https://stackoverflow.com/q/477146434 [7]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.fields.files.FieldFile