Take the 2-minute tour ×

Say I accidentally deleted a django.contrib.auth.models.User entry in django, where it cascade deleted all the rows that were affected.

What would I have to do to restore that user from a backup?

I'm assuming the steps would be:

  1. Load the backup on a separate machine
  2. Identify the rows affected by a cascade delete of an Auth User
  3. Copy those rows from the backup on the separate machine to the affected machine

What tools/scripts can I use for steps 2 and 3? Do I need to write my own or are there built in utilities that may help?

share|improve this question
add comment

2 Answers

Restore the database and enter /admin/. Go to User model and try deleting same user. Admin should ask you if you are certain and display you information which other objects will get deleted as of cascade. This is what you can get easily and for free in Django.

share|improve this answer
Agreed, but was looking for a way to get that same information in the shell? –  user749618 Jan 4 '12 at 17:43
I have no idea, if there is similar capability for shell. –  gruszczy Jan 4 '12 at 18:05
add comment

The admin app uses the get_deleted_objects function in django.contrib.admin.util to find the related objects.

In the shell, you could import this function. However it will take a bit of work to understand the required arguments. It might be simpler to use the admin website as @gruszczy suggests in his answer.

share|improve this answer
add comment

Your Answer


