To enable many-to-one relations in bulk_create the "to_field" of the
ForeignKey is defined via a UUIDField with a uuid.UUID4 default value.
Without the ignore_conflicts=True option of bulk_create it works well in
all Django versions.
But if ignore_conflicts=True is needed since some of the objects using in
the bulk_create may already be saved to the DB then it works only for
Django < 3.2.
With Django >= 3.2 (including 4.0.4) it fails with:
ValueError: bulk_create() prohibited to prevent data loss due to unsaved
related object 'reporter'.
Find attached a test app which reproduces this issue with a minimal
example, see
mysite/polls/models.py and mysite/polls/tests.py
--
Ticket URL: <https://code.djangoproject.com/ticket/33649>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "mysite.zip" added.