The easiest way to migrate a Django project from MySQL to PostgreSQL

I would like to convert my Django project database from MySQL to PostgreSQL. Unfortunately, I cannot just use the Django management commands "dumpdata" and "loaddata" because my database tables are too large. I already read the article http://www.ofbrooklyn.com/2010/07/18/migrating-django-mysql-postgresql-easy-way/ , but it seems that to use this method in practice, I still need to turn it into something like a control command that iterates over available models when it copies model instances and when it resets sequences. Moreover, it is not very fast, because it calls save () for each instance of the model.

Is there a better way to migrate? Actually, I would prefer to do "mysqldump", somehow convert the dump from MySQL to PostgreSQL format, and then load it into PostgreSQL. What part of the software would you recommend to perform such a dump conversion and correctly convert from MySQL data types to PostgreSQL, for example tinyint (1) to boolean?

Edit Thank you all for your help. I successfully migrated my database using the utility https://github.com/maxlapshin/mysql2postgres . However, I still had to reset the sequences in the resulting PostgreSQL database after importing the dump.

+4
source share
2 answers

There are several converters for it, for example, this one in Ruby: https://github.com/maxlapshin/mysql2postgres

+3
source

If your dataset is large and you need to do some kind of conversion, you can use open source solutions such as talent studio and the pentaho teapot project to create a map and it will take care of the rest; but this may be redundant if you do not want to do any transformations (or your data set is really, really big).

EnterpriseDB (the company behind postgresql) provides a data migration page that does this with a guide if you want to do it yourself.

py-mysql2pgsql The python package is another option.

0
source

Source: https://habr.com/ru/post/1384685/


All Articles