mysql - Django : DoesNotExist: matching query does not exist -


i'm in process of moving django (v1.1) project mysql postgresql (fun!) , transferring of data. attempted use manage.py dumpdata option, server we're using rather old , take long time (it seems want load memory). came small script process each app , each model under it, simplified version shown below:

 def dumpjson(model, outfile):       try:             data = serializers.serialize("json", model.objects.all(),indent=4)                     except model.doesnotexist:             print model.__name__ , "does not exist (not object)"     except objectdoesnotexist:             print model.__name__ , "issue data, not sure what...."              data = serializers.serialize("json", model.objects.all(),indent=4)             data = data.decode("unicode_escape").encode("utf8")             out = open(outfile, "w")             out.write(data)             out.close()          def main():     app in get_apps():                            model in get_models(app):                       print " -- dumping:", model.__name__                     outfile = "json_dumps/" + model.__name__ + ".json"                                             dumpjson(model, outfile) 

however, if remove try catch statements, following error:\

  -- dumping: institution   traceback (most recent call last):   ...(nasty stacktrace)....         unity.trip.models.doesnotexist: usnwrdata matching query not exist. 

my model defined so:

class usnwrdata(models.model):     rank = models.positiveintegerfield(blank=true, null=false)     name = models.charfield(max_length=255, blank=true, null=false)     state = models.charfield(max_length=10, blank=true, null=false)     public = models.booleanfield(blank=true, null=false)     type = models.foreignkey(usnwrtype)  class institution(models.model):     name = models.charfield(max_length=200)     parent_institution = models.foreignkey('self', blank=true, null=true)     location = models.foreignkey(location, blank=true, null=true,related_name='old_location')     type = models.foreignkey(institutiontype, blank=true, null=false )     usnwr = models.foreignkey(usnwrdata, blank=true, null=true)     locationnrm = models.foreignkey(locationnrm, blank=false, null=true) 

as understand it, cause of error sort of data mismatch or missing foreign keys. given above model, seems issue? i'm having bit of trouble , original author long gone. appreciated!

edit: full stack trade is:

 -- dumping: institution  traceback (most recent call last):  file "custom_dump.py", line 38, in <module>     main()  file "custom_dump.py", line 34, in main     dumpjson(model, outfile)  file "custom_dump.py", line 16, in dumpjson     data = serializers.serialize("json", model.objects.all(),indent=4)  file "/usr/local/lib64/python2.5/site-packages/django/core/serializers/__init__.py", line 91, in serialize     s.serialize(queryset, **options)  file "/usr/local/lib64/python2.5/site-packages/django/core/serializers/base.py", line 48, in serialize     self.handle_fk_field(obj, field)  file "/usr/local/lib64/python2.5/site-packages/django/core/serializers/python.py", line 48, in handle_fk_field     related = getattr(obj, field.name)  file "/usr/local/lib64/python2.5/site-packages/django/db/models/fields/related.py", line 315, in __get__     rel_obj = queryset(self.field.rel.to).using(db).get(**params)  file "/usr/local/lib64/python2.5/site-packages/django/db/models/query.py", line 349, in % self.model._meta.object_name) unity.trip.models.doesnotexist: usnwrdata matching query not exist. 

i've found django fixtures useless other purposes small dataset (say, 100 records of foo optionlist items) or test fixtures. approach problem exporting mysql tables csv.

additionally, might take @ this:

http://wiki.postgresql.org/wiki/converting_from_other_databases_to_postgresql#mysql


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -