Set a Datefields Arrayfield

Asked

Viewed 25 times

0

I need to store several dates in a Django model (I’m using version 2.1), I was able to create several fields, thus:

date1 = models.DateField(null=True, blank=True, verbose_name="Data da parcela 1")
date2 = models.DateField(null=True, blank=True, verbose_name="Data da parcela 2")
...

But this is not very practical, including the amount of dates (dates of installments) should be variable. Searching I saw that there is Arrayfield and I tried the following:

dates = ArrayField(
    models.DateField(null=True, blank=True),
)

But when I run Migration the error appears:

Django.db.utils.Programmingerror: column "Dates" is of type date[] but default Expression is of type integer HINT: You will need to rewrite or cast the Expression.

Why are you saying that the default is integer? Does anyone know a better way to do this?

Note: Leaving the default as datetime.now would be bad, has some kind of "datetime.null" or something like that?

  • Just to confirm, you’re using a fake bank?

  • Anyway, another alternative would be to try to set also to the arrayfield a "Blank=True"

  • yes, postgres @Zulo

  • All right, so let’s try to define something like: Dates = Arrayfield(models.Datefield(null=True, Blank=True), Blank=True)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.