PostgreSQL doesn't convert types when comparing values automatically as MySQL does. String values in PostgreSQL queries are always quoted with 'single quotes'. Typically, these are the differences that you might have to keep in mind: The code running Django ORM will run smoothly, but very likely there will be issues with raw SQL, QuerySet's extra() method, and type conversions. When the database is successfully migrated, we should run Django project tests and fix all PostgreSQL-specific problems in the project's code. In that case, clean up the MySQL database, update your local copy, recreate PostgreSQL database with dropdb and createdb commands, run Django migrations to create the database schema, and copy the data again. If in addition you get errors about duplicated data or tables with foreign keys to missing entries, you will need to fix the issues at MySQL database and then repeat the process. These can probably be ignored, because the script will take its best guess how to convert data when importing. Typically you will get a bunch of warnings about type conversions. Make sure that your production MySQL database migration state is up to date:Įnter fullscreen mode Exit fullscreen mode You need to have functional tests to check if all pages are functioning correctly and unit tests to check at least the most critical or complex classes, methods, and functions. One prerequisite for the migration are passing tests. I learned about this tool from Louise Grandjonc, who was giving a presentation about PostgreSQL query optimization at DjangoCon Europe 2017. So what does it take to migrate from MySQL to PostgreSQL? We will do that in a few steps and we will be using pgloader to help us with data migration. For a newcomer, the best client that I know - pgAdmin (macOS, linux, windows) - might seem too complex at first, compared with MySQL clients, but as you have Django administration and handy ORM, you probably won't need to inspect the database in raw format too often. multidimensional arrays, JSON fields, key-value pair fields, special case-insensitive text fields, range fields, special indexes, full-text search, etc. PostgreSQL enables using several vendor-specific features that were not possible with MySQL, e.g. And the database of choice for most professionals happens to be PostgreSQL. Something that most top Django developers use. It should be something that is fast, reliable, and well supports ANSI standards of relational databases. When one thinks about scaling a project, they have to choose something more suitable. Also I had database integrity errors which appeared in the MySQL databases throughout years because of different bugs at the application level. However, in my professional life there were unfortunate moments, when databases from different projects crashed because of large queries or file system errors. Also there are great clients for easy management, like phpMyAdmin (web), HeidiSQL (windows), or Sequel Pro (macOS). It is known and used widely and has good documentation. MySQL database has proven to be a good start for small and medium scale projects. In this article I will guide you through the steps I had to take to migrate Django projects from MySQL to PostgreSQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |