Opened 7 years ago
Closed 7 years ago
#29171 closed Bug (worksforme)
PostgreSQL specific model fields - ArrayField: Type Mismatch
Reported by: | Pal | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Normal | Keywords: | Postgres Array Query |
Cc: | Mariusz Felisiak | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When you define ArrayField as models.CharField, the query fails. But if you define ArrayField as models.TextField, the query succeeds.
Not Working: ArrayField(models.CharField(max_length=200), blank=True)
Working: ArrayField(models.TextField(blank=True))
Change History (8)
comment:1 by , 7 years ago
Type: | Uncategorized → Bug |
---|
follow-up: 3 comment:2 by , 7 years ago
comment:3 by , 7 years ago
Replying to Simon Charette:
Could you provide a traceback and more details about how it fails?
Does it happen when you define a model using
ArrayField(CharField())
, when performing a query annotation?
Yes. When I defined the model as shown in the documentation at https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#querying-arrayfield , the query fails. But if I change models.CharField to models.TextField, the query succeeds.
Here are the error statements from apache2 error log:
psycopg2.ProgrammingError: operator does not exist: text[] @> character varying[]
django.db.utils.ProgrammingError: operator does not exist: text[] @> character varying[]
May be we need to change the documentation to reflect the change above. Thanks.
comment:4 by , 7 years ago
Cc: | added |
---|
follow-up: 6 comment:5 by , 7 years ago
Please show the model and the query. Perhaps you could write it as a test for tests/postgres_tests/test_array.py
using CharArrayModel
.
comment:6 by , 7 years ago
Replying to Tim Graham:
Please show the model and the query. Perhaps you could write it as a test for
tests/postgres_tests/test_array.py
usingCharArrayModel
.
One thing I want to mention is that this table was already created in Postgres and I am adding that to the models.py. As I said, if I define as ArrayField(models.CharField...), query does not work where as ArrayField(models.TextField...) works. So someone can test and verify this. Thanks.
comment:7 by , 7 years ago
I'm still not sure we have enough details to reproduce the issue. What does the SQL for the table look like, what does your model look like, and what does the failing QuerySet look like?
comment:8 by , 7 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Could you provide a traceback and more details about how it fails?
Does it happen when you define a model using
ArrayField(CharField())
, when performing a query annotation?