I have a problem inserting into a field using an ArrayField with an internal JSONField.
models.py
locations = ArrayField(JSONField(null = True,blank = True), blank=True, null = True)
Embed
location_arr = [{"locations" : "loc1","amount":Decimal(100.00)},{"locations" : "loc2","amount":Decimal(200.25)}] instance.locations = location_arr instance.save()
When i do this i got
The "location" of the column is of type jsonb [], but the expression is of type text []
LINE 1: ... d "= 2517," locations "= ARRAY ['{" loc ...
Hint: You will need to rewrite or apply the expression.
So, I tried to reset it using:
import json location_arr = [{"locations" : "loc1","amount":Decimal(100.00)},{"locations" : "loc2","amount":Decimal(200.25)}] instance.locations = json.dumps(location_arr) instance.save()
then i got it
LINE 1: ... d "= 2517," locations "= '[{" loc ": ...
DETAILED DESCRIPTION: "[" must enter explicitly specified array sizes.
I use:
- Django 1.9
- Python 2.7
- Postgres 9.4.10
- psycopg2 2.6.2
source share