Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy database in use to other database in django?

Tags:

I have developed a simple django application using sqlite3. At first, I wanted to keep it simple using sqlite3 but, things are beginning to scale up (Yes, I actually started using that application with sqlite3! Shame on me...) so I want to migrate all my data to postgresql database.

Does django or another third-party provide such feature, or should I suffer for my own stupidity...

like image 673
yasar Avatar asked Aug 09 '11 20:08

yasar


People also ask

Can we use 2 databases in Django?

Django's admin doesn't have any explicit support for multiple databases. If you want to provide an admin interface for a model on a database other than that specified by your router chain, you'll need to write custom ModelAdmin classes that will direct the admin to use a specific database for content.


1 Answers

First, execute

manage.py dumpdata > out.json 

then change your DB config, migrate (or syncdb) and finally

echo "delete from auth_permission; delete from django_content_type;" | python manage.py dbshell 

(If you have Django older than 1.11, you need to use

echo "delete from django_content_type;" | manage.py dbshell 

)

Then load the JSON file:

manage.py loaddata out.json 

(as of 2013 django_contenttype is replaced with django_content_type)

like image 126
rewritten Avatar answered Sep 19 '22 18:09

rewritten