Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayField not recognized?

I have the following error message:

AttributeError: 'module' object has no attribute 'ArrayField'

Here is the relevant code segment:

from __future__ import unicode_literals
from django.db import models
from django.contrib.postgres.fields import ArrayField

class TypeStatistics(models.Model):
    bots_array = models.ArrayField(models.CharField(max_length=50), blank=True)

Any idea what can be causing this?

like image 654
ML. Avatar asked Dec 14 '22 04:12

ML.


1 Answers

Two things, first make sure that you are using Django version >= 1.8 then change the following line:

bots_array = models.ArrayField(models.CharField(max_length=50), blank=True)

to

bots_array = ArrayField(models.CharField(max_length=50), blank=True)

the django.db.models does not have an ArrayField but you have imported ArrayField from contrib postgresql so that's what you should be using.

like image 80
e4c5 Avatar answered Jan 17 '23 01:01

e4c5