Looking for django Keywords? Try Ask4Keywords

Django 指定ArrayField的最大大小


 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

当你使用size参数时,它会被传递给postgresql,后者接受它然后忽略它!因此,使用postgresql控制台很可能在上面的scoops字段中添加7个整数。