Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily convert a Django app from mySQL to PostgreSQL?

Has anyone done this? Is it an easy process? We're thinking of switching over for transactions and because mysql seems to be "crapping out" lately.

like image 491
Ryan Detzel Avatar asked Feb 11 '11 01:02

Ryan Detzel


People also ask

How do I export from MySQL to Postgres?

Create a database connection for the MySQL source (Tools -> Wizard -> Create database connection) Create a database connection for the PostgreSQL source (as above) Run the Copy Tables wizard (Tools -> Wizard -> Copy Tables) Run the job.

Is PostgreSQL good for Django?

We've seen how Django is the most capable web framework, and PostgreSQL is the most robust and dependable RDBMS. As a developer, you can leverage the versatility of PostgreSQL to work with almost any type of data and the unbeatable features of Django to develop fast and secure web applications.

Which is easier MySQL or PostgreSQL?

MySQL is a simpler database that's fast, reliable, well understood, and easy to set up and manage. PostgreSQL is an object-relational database (ORDBMS) with features like table inheritance and function overloading, whereas MySQL is a pure relational database (RDBMS).


2 Answers

Converting MySQL database to Postgres database with Django

First backup your data of the old Mysql database in json fixtures:

$ python manage.py dumpdata contenttypes --indent=4 --natural-foreign > contenttype.json
$ python manage.py dumpdata --exclude contenttypes --indent=4 --natural-foreign > everything_else.json

Then switch your settings.DATABASES to postgres settings.

Create the tables in Postgresql:

$ python manage.py migrate

Now delete all the content that is automatically made in the migrate (django contenttypes, usergroups etc):

$ python manage.py sqlflush | ./manage.py dbshell

And now you can safely import everything, and keep your pk's the same!

$ python manage.py loaddata contenttype.json
$ python manage.py loaddata everything_else.json

Tested with Django==1.8

like image 181
Michael van de Waeter Avatar answered Sep 25 '22 19:09

Michael van de Waeter


I just used this tool to migrate an internal app and it worked wonderfully. https://github.com/maxlapshin/mysql2postgres

like image 23
Philip Southam Avatar answered Sep 24 '22 19:09

Philip Southam