Django 4.1 : bulk_create() can only be used with concrete fields in update_fields

313 Views Asked by At

I try to use the new arguments updata_fields and unique_fields in Django 4.1, but I realy don't know what to do about this error...

Here is my model :

class Sequence(models.Model):
    id = models.CharField(max_length=50, primary_key=True)
    sequence = models.TextField()
    position = models.IntegerField(default=0, validators=[MinValueValidator(0)])
    isCds = models.BooleanField(default=True) # True: cds | False: peptidic

    genome = models.ForeignKey(Genome, on_delete=models.CASCADE)

and the code that raise the error :

sequenceFields = [field.name for field in sequenceFields if field.name != 'id']
self.stdout.write(self.style.SUCCESS(str(sequenceFields))) # Just to be sure the list is correct
Sequence.objects.bulk_create(sequences, update_conflicts=True, update_fields=sequenceFields, unique_fields=['id'])

And I have the ouput : ValueError: bulk_create() can only be used with concrete fields in update_fields.

I looked for an example of this use of bulk_create online but I could not find one.

0

There are 0 best solutions below