06.08.2019
Posted by 

This page provides python code examples for django.db.models.get_models. From django.db.models import get_app, get_apps, get_models datadir, verbose, stdout = options.datadir, options.verbose, options.stdout if verbose: print 'Begin to dump data for%s format. ERROR('Unable to serialize database:%s n'% e)). I try to dump my database in Postgres to json so that I can load it into my test system. Executing manage.py dumpdata gives me an error: Unable to serialize database: Decimal('349.00') is not JSON serializable Some googling finds ticket number 3324, a problem with the serializer.

Active2 years ago

I'm running a command to dump my database contents into json format:

python manage.py dumpdata <appname>.<modelname> > file.json The body reset diet ebook download.

However, it is not dumping my many-to-many field which is called category_id. Well in fact, it is dumping it but the field is consistently empty. Why??

I have tried calling that table directly (which is a category mapping) as such:

python manage.py dumpdata <appname>.<modelname_category_id> > file.json

and I get the following error:

Error: Unable to serialize database: Category matching query does not exist.

Django dumpdata error unable to serialize database

I'm using Django 1.2.1 and SQLite backend.

Any hints?

UPDATE: I have tried deleting all rows in the modelname.category_id table, and even with only one row I still get this error.

The table is defined as followsid: integer PRIMARY KEYunipart_id: integercategory_id: integer

and both unipart_id and category_id fields are valid and exist.

user1328021
user1328021user1328021
2,21011 gold badges35 silver badges70 bronze badges

2 Answers

Probably is because the foreign key that you have in Category is not filled in some rows, check this web: http://wiki.ddenis.com/index.php?title=Django._Error:_Unable_to_serialize_database:_*_matching_query_does_not_exist.

HarchetHarchet
Pang
7,20716 gold badges68 silver badges108 bronze badges
David RestrepoDavid Restrepo

Not the answer you're looking for? Browse other questions tagged pythondjango or ask your own question.

Active2 years, 11 months ago

I want to make a dump in django irrespective of database I am using and can be loaded later. The command 'dumpdata' is perfect for this, but it is printing output on console. More over I am calling it using call_command function so I cannot store its content in any variable as it is printing output on console.

Error

Please let me know how store dump to a file using dumpdata or any other command or api.

Thanks

DatabaseParitosh SinghParitosh Singh
4,1084 gold badges30 silver badges50 bronze badges

5 Answers

You can choose a file to put the output of dumpdata into if you call it from within Python using call_command, for example:

However, if you try calling this from the command line with e.g. --stdout=filename.json at the end of your dumpdata command, it gives the error manage.py: error: no such option: --stdout.

So it is there, you just have to call it within a Python script rather than on the command line. If you want it as a command line option, then redirection (as others have suggested) is your best bet.

bouteillebleubouteillebleu

You just use it like that:

After that action, there will be data_dump.json file in the directory in which you executed that command.

There are multiple options coming with that, but you probably already know it. The thing you need to know is how to redirect output from standard output into some file: you perform that action by putting > before file name.

To append something to the file you would use >>, but since you are dumping the data from Django and the output is most likely JSON, you will not want that (because it will make JSON invalid).

TadeckTadeck
97.3k20 gold badges127 silver badges180 bronze badges

Outputs to standard output all data in the database associated with the named application(s).

As you know, you can redirect standard output to a file:

dani herreradani herrera
30.1k3 gold badges54 silver badges114 bronze badges

Django Dumpdata Error Unable To Serialize Database In Windows 10

As it is mention in the docs, in order to dump large datasets you can avoid the sections causing problems, and treat them separately.

The following command does generally work:

In case you can export later the excluded data:

EvhzEvhz
4,2394 gold badges26 silver badges49 bronze badges

In Linux, you can just pipe the console output to a file.

manage.py dumpdata > file

stryderjzwstryderjzw

Django Dumpdata Error Unable To Serialize Database Download

Not the answer you're looking for? Browse other questions tagged pythondjangodjango-modelsdjango-commands or ask your own question.