I am sure that something is incorrectly configured here, but I do not understand what it is.
In Django, I have a model field that says the following:
short_url_slug = AutoSlugField(slugify=short_url_slugify, populate_from=id, blank=False, unique=True)
The south creates migration (seemingly) correctly:
'short_url_slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'None', 'blank': 'True'}),
My Postgresql DB - UTF8:
\l (MyDBName) | (username) | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
And I have a unicode character in real life:
u'\xa4'
But when I write this to the database and try to read it, I get:
In [3]: this_instance.short_url_slug Out[3]: u'o'
Thoughts? My suspicion is that Postgresql should have a different character encoding, but I'm not sure what it should be (if so) or how to do it.
Edit with additional information
SELECT version(), current_setting('standard_conforming_strings') AS scs; PostgreSQL 9.2.4 on x86_64-apple-darwin11.4.2, compiled by i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00), 64-bit | on (END)
Python version:
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
Django Version:
In [2]: django.VERSION Out[2]: (1, 5, 1, 'final', 0)
psycopg2:
$ pip freeze | grep psycopg2 psycopg2==2.5
Raw log from postgresql:
LOG: statement: UPDATE [...lots of stuff removed...] "short_url_slug" = 'o' [... rest of the stuff ...]
So it looks like he didn't even get into Postgresql. But when I break the line in the insert, the variable definitely has a unicode value.
(Pdb) response.short_url_slug u'\xd6'
(this is after assignment in Python, but before response.save ())
More output:
The way I discover that Unicode is becoming popular is that the restriction on the uniqueness of the database is violated. This can be tested while displaying this content in the model (with disabling):
In [11]: all = Response.objects.all() In [12]: all[0].short_url_slug Out[12]: u'o' In [13]: all[4].short_url_slug Out[13]: u'o' In [14]: all[4].short_url_slug == all[0].short_url_slug Out[14]: True