Code

Opened 6 years ago

Closed 6 years ago

#6726 closed (invalid)

python manage.py dumpdata doesn't sort objects in correct order

Reported by: leotr Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: loaddata, dumpdata
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have to manually reorder objects in initial_data.<xml, json> before i run python manage.py loaddata.
I think that firstly python manage.py dumpdata command should:

  1. dump objects without foreign keys
  2. dump objects having relations to objects in 1.
  3. dump objects having relations to objects in 2.

...
until all objects are loaded.

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

What you are proposing is impossible in the generic case. As soon as you have cycles in your data, it's impossible to resolve an order that doesn't have forward references.

Luckily, you don't need to reorder the objects in fixtures as long as you use a database backend that has actual support for handling referential integrity. I'm going to take a wild stab in the dark and guess that you're using MySQL with InnoDB tables. The documentation for loaddata mentions why this might be a bad idea.

http://www.djangoproject.com/documentation/django-admin/#loaddata-fixture-fixture

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.