liuyang1520 / django-command-extensions

Automatically exported from code.google.com/p/django-command-extensions
MIT License
0 stars 0 forks source link

dumpscript wish: Order by ForeignKeys #53

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I think it would be a nice addition if dumpscript could order the models by
ForeignKey relations before dumping, so MySQL won't cry about fields which
are still Null (because the relations get setup later on in the script..
too late :/)

Some code could perhaps taken from http://www.djangosnippets.org/snippets/662/

Original issue reported on code.google.com by philipp....@gmail.com on 16 Sep 2008 at 8:48

GoogleCodeExporter commented 8 years ago
Are you talking about model ordering or object ordering? Dumpscript already 
orders
the models to avoid dependency problems as much as possible using the function
queue_models().

Object-level ordering is also done if I remember correctly. If a ForeignKey 
hasn't
been processed yet, a DoLater exception is raised and the object is thrown back 
to
the end of the queue to be processed later. If it detects circular references, 
it
gives up and sets the foreign key to null, trying again afterwards.

Can you give me an example of something that trips it up? I'm thinking about 
using
placeholders soon, to deal with circular dependencies, but that might cause 
other
problems, especially if the placeholder has an effect on custom code.

Original comment by e.willha...@gmail.com on 16 Nov 2008 at 2:57

GoogleCodeExporter commented 8 years ago
By the way, sorry for the delay, I missed this ticket and it never got starred.

Original comment by e.willha...@gmail.com on 16 Nov 2008 at 2:57

GoogleCodeExporter commented 8 years ago
Ok, looking at the code it looks like DoLater is caught at the field level, 
meaning
that field is simply skipped.

I think it would be nicer if DoLater is passed on, and the entire object is 
skipped
to be processed later. I'll look into this over the next couple of weeks.

Original comment by e.willha...@gmail.com on 16 Nov 2008 at 3:13

GoogleCodeExporter commented 8 years ago

Original comment by e.willha...@gmail.com on 15 Mar 2009 at 10:32