1

My django application has some 500 records in various tables in the database(postgres).I want to add some 4 more records to a particular table.I have created(edited by hand )a json file that represents the new data to be added and I have taken care to provide them new ids so that they don't conflict with existing records in db.

What I want to know is whether the existing data(the original 500 records) will be deleted when I call

django-admin.py loaddata mydata.json

Or will the new data be added to the existing records?

p.s: Is there any way I can convert the whole data in db into a json file?Using serializers is time consuming when there are many model classes.

1 Answer 1

1

You should do a backup before the loaddata if it's mission critical.

That said, loaddata just adds or updates records, it doesn't delete the existing ones.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you..but how do you take a backup of data from postgres in ubuntu?
That's actually another question. The command to use is pg_dump. For example you can dump with: pg_dump -x -F c -f /path/to/dump database_name. Then restore with: pg_restore --disable-triggers -d database_name /path/to/dump. Read the docs on these commands flags please.
django-admin also has a tool for dumping the data from your database in a format that can later be read by loaddata: docs.djangoproject.com/en/dev/ref/django-admin/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.