1

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.

Community
  • 1
  • 1
Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64

2 Answers2

4

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

pyjavo
  • 1,598
  • 2
  • 23
  • 41
vankovsky
  • 84
  • 3
  • The "Multiple database example" does not help in the case where you have multiple databases for a single app. Some models in my app are in one SQLite, while others are in another. I have not been able to figure out how the `allow_migrate` function needs to work in order to solve this issue, right now when I try to use `dumpdata` with this app I get and output of `[]`, nothing is dumped. However all other aspects of the app appear to be working fine. – user5359531 Mar 13 '19 at 20:17
  • if would be helpful if you could provide a working example for `allow_migrate`, because mine looks exactly like what is shown in the docs linked there and it still does not work. – user5359531 Mar 14 '19 at 19:28
0

I did not have multiple databases but still I was getting empty fixtures when dumped.

I had to add a separate empty models.py in my app to get the data dumped.

subha.py
  • 463
  • 3
  • 18