Django: ProgrammingError: Can’t Adapt
I find I get an error like this far too often, but not often enough to remember why I got the problem the previous time. For my own sanity, I’m blogging about it for reference. The error itself is not very descriptive:
Exception Type: ProgrammingError
Exception Value: can’t adapt
Unless there is something I’m forgetting, it seems 100% of the time it has been a simple error. I use the get_or_create function to retrieve a model, but I don’t account for the “created” variable. So then I try to use the tuple as a model object somewhere and it throws this error.
For example, here is the wrong way:
person = Person.objects.get_or_create(first_name="Dustin", last_name="Davis") print person.first_name
And now for the correction:
person, created = Person.objects.get_or_create(first_name="Dustin", last_name="Davis") print person.first_name
Related posts:
- Django & Djson… er, JSON I must admin this is my first attempt at even...
- Django: Login Form on Every Page Up to the point, when it has come to Django...
- Copy Model Object in Django I ran into a situation where I wanted to created...
- One Click Django Project Publishing I was reading The Joel Test and I got to...
- Mobile App on Subdomain with Django I’ve noticed a fairly common pattern arising with mobile and...
Related posts brought to you by Yet Another Related Posts Plugin.
January 28, 2010
Tags: django Posted in: Programming & Internet




9 Responses
In case anyone finds your post via search, “Can’t Adapt” exceptions are also very common when using PostgreSQL/pyscopg. For instance, if you have a table column of text, and you try to run a SQL statement that excepts it to be numeric (such as an average or sum aggregate) you’ll get Can’t Adapt exceptions.
The easiest way to determine ‘why’ is to consult your PostgreSQL logs.
Out of curiosity, have any idea why it throws “ProgrammingError” instead of “AttributeError”? The latter would at least give a clue of what’s wrong.
For me, this has always meant I’m trying to save/create data which the database will not accept, such as None (NULL) into a non-NULL column.
We had this problem on a server running mod_python with two different applications. With just one application there was no problem.
We moved to a wsgi configuration and we haven’t received any “can’t adapt” problems.
That’s the only way to go when you work on computers, I do research from time to time and my computer tends to get a lot of viruses when I go to sites not much travelled. To keep track of which web-pages have these viruses you need to write them down to avoid returning to them. In light of all this it’s also a good idea to keep your work saved as well including your research links.
Wir hatten dieses Problem auf einem Server mit mod_python mit zwei verschiedenen Anwendungen. Mit nur einer Anwendung hatte keine Probleme
Hi I think your error is due to some syntax error. I do not know much about computer programming but I think syntax error cam be. One of my friend has similar kind of error and he checked his syntax
Synax you say, that would make sense LOL
lol, I’ve had this issue a thousand times over where I’m programming and have an error I’ve seen a thousand times but it still takes me a short while to figure it out… good thinking on blogging about it
Leave a Reply