Django dumpdata output is empty

2019-08-20 16:15发布

问题:

we have a Django 1.4.5 project with a PostgreSQL 9.3 backend. Unfortunately we are facing the problems when attempting to create fixtures for one of the apps (which is called sddb).

The database is full of objects that belong to sddb app:

(venv)[root@dl380p1 team112]# ./manage.py shell
>>> from sddb.models.media import Metadata
>>> len(Metadata.objects.all())
22916

However the dumpdata output is empty:

(venv)[root@dl380p1 team112]# ./manage.py dumpdata sddb
[]

Explicit pointing of database (mentioned here) didn't help:

(venv)[root@dl380p1 team112]# ./manage.py dumpdata --database=project_test sddb
[]

For the other apps dumpdata is working properly:

(venv)[root@dl380p1 team112]# ./manage.py dumpdata reports | wc -c
239811

I don't want to use the entire table dumps (pgdump) due to obvious reasons. Hope to find right solution here.

回答1:

I had the same problem and it was related to DB routers. Just make sure that a router processes correctly the allow_migrate method (one of routers should return True or True-like value by default). See more examples here: Django Multiple databases Examples