unique_together in bulk_create

22 Views Asked by At

this is my model:

class Reminder(models.Model):
    timestamp = models.DateTimeField()
    time_frame = models.CharField(default = "5minutes" , max_length=30,choices=[
        ("5minutes","5minutes"),
        ("15minutes","15minutes"),
        ("30minutes","30minutes"),
        ("1hour","1hour"),
        ("4hours","4hours"),
        ("1day","1day")
    ])
    coin = models.ForeignKey(Coin,on_delete=models.CASCADE)
    class Meta:
        unique_together = ["coin","time_frame"]

i want to use bulk_create command for create a lot of object from this model. options of bulk_create is update_fields and unique_fields. but i have unique_together fields. what i suppose to do for this code:

Reminder.objects.bulk_create(reminders, update_conflicts=True,update_fields=['timestamp'],batch_size=1000)
0

There are 0 best solutions below