skip below for answer
I did figure out the solution but I don't think the documentation around this is very good. Leaving with better searchability for others
I am attempting to use a generic set of emails to create a contact group composed of a list of external emails mixed with a group users. In the model I am using this:
class ContactGroup(models.Model):
users = models.ManyToManyField(settings.AUTH_USER_MODEL)
emails = ArrayField(CIEmailField(), default=list)
Everything works well with this code until I try to run tests. I get this error when trying to run tests on my project.
django.db.utils.ProgrammingError: type "citext[]" does not exist
LINE 1: ...RIMARY KEY, "role" varchar(16) NOT NULL, "emails" citext[] N...
I have a limited understanding of databases (as I think can be an issue using something like django which does all that work for me), but I know that this is not an issue with the database itself as it works when actually running it. It only seems to be an issue with how django is setting up the test database. I have seen posts where it seems to indicate that the extension is installed too late in the process, but I don't think that is my issue here as I never had to install any extensions to get this to work in the first place - I believe it is part of core in my postgresql version.
I am able to get this to work if I just allow null to be true and drop the default value altogether.
If I change this line below then I have no issues running tests but I get a warning to use a callable instead of an instance of list.
- emails = ArrayField(CIEmailField(), default=list)
+ emails = ArrayField(CIEmailField(), default=[])
Now I seem to be able to do a little bit of a hackish thing by setting up the test database with the instantiated list, but then switching my code back to the callable and then running tests using "--keepdb".
I also have another model which uses an ArrayField of CharField, with default=list, and that does not seem to be the issue. It must be something about the CIEmail or CIText field and the ArrayField together causing the issue.
I am running PostgreSQL 11.5, compiled by Visual C++ build 1914, 64-bit