djangonauts / django-pgjson

PostgreSQL json field support for Django
http://djangonauts.github.io/django-pgjson/
Other
131 stars 39 forks source link

South migrations set incorrect default. #16

Closed tomplayford closed 9 years ago

tomplayford commented 9 years ago

Postgres 9.3 Django 1.6.10

Django model field:

    json_permissions = JsonField(default={})

South migration of:

    # Adding field 'Staff.json_permissions'
    db.add_column(u'store_staff', 'json_permissions',
                  self.gf('django_pgjson.fields.JsonField')(default={}, null=False, blank=False),
                  keep_default=False)

when run, creates this, SQL:

    ALTER TABLE "store_staff" ADD COLUMN "json_permissions" json NOT NULL DEFAULT <django_pgjson.fields.JsonAdapter object at 0x10e7db0d0>;

Clearly there's something up with the registration of postgres json adapter. The test suite (with the exception of the jsonb tests) run correctly against the same DB. My only thought so far is that it's something to do with South's db backend.

sbussetti commented 9 years ago

It's actually a bug with the string representation of the Json adapter of psycopg2. Make sure you have psycopg2>=2.6

niwinz commented 9 years ago

Seems to be working correctly with newer versions of psycopg2.