Changes between Initial Version and Version 1 of Ticket #33649


Ignore:
Timestamp:
Apr 18, 2022, 12:03:33 AM (2 years ago)
Author:
Mariusz Felisiak
Comment:

Thanks for this report. This behavior was intentionally changed in 10f8b82d195caa3745ba37d9424893763f89653e to prevent possible data loss. Using ignore_conflicts=True tells the database to ignore failure to insert any rows that fail constraints such as duplicate unique values, but also disables setting the primary key on each model instance (as documented). Therefore a reporter instance doesn't have a primary key set. You need to attached already saved reporter to the article before bulk_create().

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33649

    • Property Cc Hannes Ljungberg added
    • Property Component UncategorizedDatabase layer (models, ORM)
    • Property Resolutioninvalid
    • Property Status newclosed
    • Property Summary bulk_create with ignore_conflicts=True and ForeignKey failsbulk_create() with ignore_conflicts=True and ForeignKey fails
  • Ticket #33649 – Description

    initial v1  
    66But 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.
    77With Django >= 3.2 (including 4.0.4) it fails with:
    8 ValueError: bulk_create() prohibited to prevent data loss due to unsaved related object 'reporter'.
     8`ValueError: bulk_create() prohibited to prevent data loss due to unsaved related object 'reporter'`.
    99
    1010Find attached a test app which reproduces this issue with a minimal example, see
Back to Top