Changes between Initial Version and Version 1 of Ticket #10244, comment 19


Ignore:
Timestamp:
Jun 2, 2022, 9:51:03 AM (2 years ago)
Author:
dennisvang

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #10244, comment 19

    initial v1  
    1818- `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`
    1919
    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):
     20The 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]:
    2121
    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.
    2323
    2424So, currently, we cannot make a `FileField` unique and optional at the same time.
     
    2626Why not just bite the bullet and make a backward incompatible change, for the sake of consistency?
    2727
    28 
    29 [1]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.FileField.storage
    30 [2]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#filefield
    31 [3]: https://stackoverflow.com/q/8850415
    32 [4]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.Field.null
    33 [5]: https://stackoverflow.com/q/4771464
    34 [7]: https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.fields.files.FieldFile
Back to Top