Django: unable to adapt error while importing data from postgres database

I have a strange error when installing fasteners from dumped data. I am using psycopg2 and django1.1.1

silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'. Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last): File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle obj.save() File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 163, in save models.Model.save_base(self.object, raw=True) File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base result = manager._insert(values, return_id=update_pk) File "/opt/local/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert return insert_query(self.model, values, **kwargs) File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query return query.execute_sql(return_id) File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/subqueries.py", line 320, in execute_sql cursor = super(InsertQuery, self).execute_sql(None) File "/opt/local/lib/python2.5/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql cursor.execute(sql, params) File "/opt/local/lib/python2.5/site-packages/django/db/backends/util.py", line 19, in execute return self.cursor.execute(sql, params) ProgrammingError: can't adapt 

First I checked for similar issues on the Internet. This one seemed to be very connected: http://code.djangoproject.com/ticket/5996 , since my data has many characters without ASCII

But actually I checked my django installation, and there it is good there

Could you advise what is wrong.

====

Continuation of the investigation after adding a press statement, as suggested in the first response. The log is as follows:

 silver:probsbox oleg$ python manage.py loaddata /Users/oleg/probs.json Installing json fixture '/Users/oleg/probs' from '/Users/oleg/probs'. <DeserializedObject: Novice> <DeserializedObject: Junior> <DeserializedObject: Chess enthusiast> <DeserializedObject: Experienced player > <DeserializedObject: Smart player> Problem installing fixture '/Users/oleg/probs.json': Traceback (most recent call last): File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py", line 153, in handle print obj File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 155, in __repr__ return "<DeserializedObject: %s>" % smart_str(self.object) File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 107, in smart_str return str(s) File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 335, in __str__ return force_unicode(self).encode('utf-8') File "/opt/local/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode s = unicode(s) File "/Users/oleg/Sites/probsbox/registration/models.py", line 58, in __unicode__ return u"%s profile" %(self.user.username) File "/opt/local/lib/python2.5/site-packages/django/db/models/fields/related.py", line 257, in __get__ rel_obj = QuerySet(self.field.rel.to).get(**params) File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 305, in get % self.model._meta.object_name) DoesNotExist: User matching query does not exist. silver:probsbox oleg$ 

Error since most recent comment

 <DeserializedObject: qwert2000 profile> 

Installation problem fixture '/Users/oleg/probs.json': Traceback (last last call): File "/opt/local/lib/python2.5/site-packages/django/core/management/commands/loaddata.py" , line 154, in the handle obj.save () File "/opt/local/lib/python2.5/site-packages/django/core/serializers/base.py", line 163, in saving models.Model.save_base ( self.object, raw = True) File "/opt/local/lib/python2.5/site-packages/django/db/models/base.py", line 495, in save_base result = manager._insert (values, return_id = update_pk) File "/opt/local/lib/python2.5/site-packages/django/db/models/manager.py", line 177, in _insert return insert_query (self.model, values, ** kwargs) File "/opt/local/lib/python2.5/site-packages/django/db/models/query.py", line 1087, in insert_query return query.execute_sql (return_id) file "/ opt / local / lib / python2. 5 / site-packages / djan go / db / models / sql / subqueries.py ", line 320, in execute_sql cursor = super (InsertQuery, self) .execute_sql (No) File" /opt/local/lib/python2.5/site-packages/django/ db / models / sql / query.py ", line 2369, in execute_sql cursor.execute (sql, params) file" /opt/local/lib/python2.5/site-packages/django/db/backends/util. py ", line 19, executed by return self.cursor.execute (sql, params) ProgrammingError: cannot be adapted

+4
source share
2 answers

Ok, I finished copying the dump from my database and restored it locally without python ...

0
source

The can't adapt occurs psycopg2 when it receives a data type that does not know how to convert to a value for an SQL statement. For example, if you accidentally pass a list, say, for a value that should be an integer, psycopg2 will raise it, this cannot adapt the error.

The faq.txt document that comes with the original psycopg2 distribution explains this as follows:

Why !cursor.execute() raise exception cannot be adapted?

Psycopg converts Python objects to a SQL string representation by looking in the object class. An exception occurs when you try to pass as a request parameter - an object for which there is no adapter registered for its class. See: Ref: adapting-new-types for information.

Probably your best first pass when detecting an abusive value is to run loaddata in fully verbose mode: python manage.py loaddata --verbosity = 2 / Users / oleg / probs.json

Well, I was hoping loaddata verbosity would work, and I would not have to admit that I never found an elegant way to debug adaptation errors with django loaddata. I used to resort to inserting print statements into the ddango loaddata function so that I can see that the values ​​are deserialized when an error occurs. I edited django/core/management/loaddata.py . Take a look at obj.save() in the handle() function. I hope this recognition inspires someone to a better solution :-)

+5
source

Source: https://habr.com/ru/post/1312991/


All Articles