djangosnippets.org: Latest snippets tagged with 'dumpdata'https://djangosnippets.org/tags/dumpdata/2017-10-07T09:58:48.674711-05:00Do Not Escape Characters When Using dumpdata Command (Tested in Django 1.11)
2017-10-07T09:58:48.674711-05:00oldcaihttps://djangosnippets.org/snippets/10625/<p>Adds <code>--pretty</code> option to django <code>./manage.py dumpdata</code> command, which produces pretty utf-8 strings instead of ugly unicode-escaped s**t:</p>
<blockquote>
<p>$ ./manage.py dumpdata app.pricingplan --indent=1</p>
</blockquote>
<pre><code>[
{
"pk": 1,
"model": "app.pricingplan",
"fields": {
"name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439",
}
},
{
"pk": 2,
"model": "app.pricingplan",
"fields": {
"name": "\u0425\u0443\u044f\u0437\u043e\u0432\u044b\u0439",
}
}
]
</code>
</pre>
<blockquote>
<p>./manage.py dumpdata app.pricingplan …</p></blockquote>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols) #4
2016-09-08T09:14:44.151728-05:00muciushttps://djangosnippets.org/snippets/10587/<p>The version of snippet that works with Django 1.9</p>
Freely redistributableutf8-friendly dumpdata management command for yaml (no escape symbols) #2
2016-09-08T09:09:16.423595-05:00muciushttps://djangosnippets.org/snippets/10586/<p>This is a revised version of https://djangosnippets.org/snippets/2921/</p>
Freely redistributableutf8-friendly dumpdata management command for yaml (no escape symbols)
2013-05-17T22:50:44.148805-05:00muciushttps://djangosnippets.org/snippets/2921/<p>This is a YAML version of http://djangosnippets.org/snipptes/2397</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols) #3
2013-05-05T12:36:38.052197-05:00inductorhttps://djangosnippets.org/snippets/2916/<p>The version of <a href="http://djangosnippets.org/snippets/2397/">snippet</a> that works with Django 1.5. Kudos to <a href="http://djangosnippets.org/users/kmike/">kmike</a> for the original snippet.</p>
Freely redistributableRemove old fields on dumpdata generated json
2011-10-21T15:46:38.312378-05:00facundo_olanohttps://djangosnippets.org/snippets/2576/<p>A small script that takes a manage.py dumpdata generated json file, and removes fields of the specified models. I needed this because i kept my initial data on a json file and after I removed a field on one of my models, the script wouldn't work anymore.</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols) #2
2011-03-19T19:39:44.551171-05:00kmikehttps://djangosnippets.org/snippets/2397/<p>This is a version of <a href="http://djangosnippets.org/snippets/2258/">http://djangosnippets.org/snippets/2258/</a> that should work with special chars (e.g. quotes) in json data.</p>
Freely redistributableutf8-friendly dumpdata management command (no escape symbols)
2010-11-12T07:37:38.374550-06:00dirolhttps://djangosnippets.org/snippets/2258/<p>Adds <code>--pretty</code> option to django <code>./manage.py dumpdata</code> command, which produces pretty utf8 strings instead of ugly unicode-escaped shit:</p>
<pre><code>$ ./manage.py dumpdata app.pricingplan --indent=1
[
{
"pk": 1,
"model": "app.pricingplan",
"fields": {
"name": "\u0411\u0430\u0437\u043e\u0432\u044b\u0439",
}
},
{
"pk": 2,
"model": "app.pricingplan",
"fields": {
"name": "\u0425\u0443\u044f\u0437\u043e\u0432\u044b\u0439",
}
}
]%
./manage.py dumpdata app.pricingplan …</code></pre>
Freely redistributableDatabase cleanup
2010-07-28T03:20:02.422562-05:00skyjurhttps://djangosnippets.org/snippets/2125/<p><strong><em>About</em></strong>
</p>
<p>I tried to dump data from my database (manage.py dumpdata) and I couldn't do it because of error:
</p>
<pre><code>User matching query does not exists
</code></pre><p>I found out that my database was filled with garbage: entries those foreigners were deleted. My table's engine is MyISAM so it allows for these …</p>
Freely redistributabledumpdata/loaddata with MySQL and ForeignKeys, as django command
2009-04-21T17:37:34.933099-05:00brondsemhttps://djangosnippets.org/snippets/1457/<p>Based on <a href="http://www.djangosnippets.org/snippets/662/">http://www.djangosnippets.org/snippets/662/</a> and updated to be runnable as custom django management command. Also added option support for --exclude=someapp --exclude=otherapp.SomeModel</p>
<p>From original description:
InnoDB tables within MySQL have no ability to defer reference checking until after a transaction is complete. This prevents most dumpdata/loaddata cycles unless the dump order falls …</p>
Freely redistributablestreaming dump_data
2009-03-29T21:03:52.979071-05:00kcarnoldhttps://djangosnippets.org/snippets/1402/<p><code>dumpdata</code> without <code>MemoryErrors</code>, with progress notification. Most of the real work is done by snippets <a href="http://www.djangosnippets.org/snippets/1400/">1400</a> and <a href="http://www.djangosnippets.org/snippets/1401/">1401</a>.</p>
<pre><code>./manage.py dumpdata_stream --format=xml > big_dump.xml
</code></pre>
<p>This is basically the stock Django <code>dumpdata</code> with a few modifications. Django devs: it's hard to reuse parts of most Django management commands. A little …</p>
Freely redistributablestreaming serializer
2009-03-29T20:55:02.602772-05:00kcarnoldhttps://djangosnippets.org/snippets/1401/<p>Trying <code>./manage.py dumpdata</code> on a huge database and getting <code>MemoryError</code>s? Here's part of your solution.
</p>
<p><a href="http://www.djangosnippets.org/snippets/1400/">Snippet 1400</a> provides a queryset_foreach utility that we've found very useful. This snippet uses it on a serializer that can output to a stream, such as the XML serializer.
</p>
<p>Management command coming momentarily...
</p>
Freely redistributableSerializing booleans correctly when doing dumpdata from a MySQL database using Django 0.96
2008-07-29T08:27:32.866839-05:00chrjhttps://djangosnippets.org/snippets/924/<p>Django 0.96 seems to have a bug when serializing from MySQL. BooleanFields are encoding as 0/1 instead of true/false. Hacking the python serializer seems to fix that. </p>
<p>The bug shows up as (fx. when using loaddata on a dump from MySQL in PostgreSQL):</p>
<pre><code>Problem installing fixture '/tmp/data.json': ERROR: column "is_staff" …</code></pre>
Freely redistributabledumpdata/loaddata with MySQL and ForeignKeys (Revision 2)
2008-03-24T11:42:17.347911-05:00cmgreenhttps://djangosnippets.org/snippets/662/<p>nnoDB tables within MySQL have no ability to defer reference checking until after a transaction is complete. This prevents most dumpdata/loaddata cycles unless the dump order falls so that referenced models are dumped before models that depend on them.</p>
<p>This code uses Ofer Faigon's topological sort to sort the models …</p>
Freely redistributabledumpdata/loaddata with MySQL and ForeignKeys
2008-01-02T09:20:40.417055-06:00cmgreenhttps://djangosnippets.org/snippets/533/<p>InnoDB tables within MySQL have no ability to defer reference checking until after a transaction is complete. This prevents most dumpdata/loaddata cycles unless the dump order falls so that referenced models are dumped before models that depend on them.</p>
<p>This code uses <a href="http://www.bitformation.com">Ofer Faigon's</a> topological sort to sort the models …</p>
Freely redistributable