Django dumpdata output is empty
Asked Answered
A

2

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.

Arita answered 8/10, 2014 at 8:20 Comment(3)
wish this questhion be helpful for youTiki
Did you find a solution to this issue already?Bewhiskered
@javidazac I don't use Django anymore...Arita
D
5

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

Dystopia answered 21/10, 2014 at 10:3 Comment(2)
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.Ruche
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.Ruche
Q
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.

Quijano answered 28/1, 2022 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.