Django ArrayField - a PostgreSQL-specific field Specifying the maximum size of an ArrayField

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

 from django.db import models, IntegerField
 from django.contrib.postgres.fields import ArrayField
 
 class IceCream(models.Model):
     scoops = ArrayField(IntegerField()  # we'll use numbers to ID the scoops
                   , size=6)  # our parlor only lets you have 6 scoops

When you use the size parameter, it's passed through to postgresql, which accepts it and then ignores it! Thus it's quite possible to add 7 integers to the scoops field above using the postgresql console.



Got any Django Question?