How to migrate data from SQLite to PostgreSQL in Django
Hi DEVs! In this post I want to talk about differences between SQLite and PostgreSQL. In addition, I will show you how to migrate your data from SQLite to PostgreSQL.
Well, SQLite and PostgreSQL are the most widely used relational database management systems. They are both open-source and free. However, they have some major differences that should be considered when choosing a database to use for your applications.
There is a lot articles on internet which covers this topic, so I will not focus on comparison of these databases.
SQLite is too "light" for real world applications, so majority of developers prefer to use MySQL or PostgreSQL for web applications. Generally, SQLite is highly useful for:
- Standalone apps
- Small apps that don’t require expansion
- Apps need to read or write files to disk directly
- The internet of things devices
- Developing and even testing
and PostgreSQL is recommended when:
- Data integrity and reliability is highly concerned.
- Custom Procedures which is extensible to run the complex task.
- Complexity with ease. PostgreSQL gives you the functionality to maintain such a complex database smoothly without limitations.
Migrate data from SQLite to PostgreSQL
Dump existing data:
Change settings.py to Postgres backend. Check this awesome tutorial by Digital Ocean:
Make sure you can connect on PostgreSQL. Then:
Run this on Django shell to exclude contentype data
Finally, run following command to load the json data:
Great! Now, your all data migrated from SQLite to PostgreSQL.
There is also interesting question on StackOverflow about MySQL vs PostgreSQL.
That's it! Make sure you are following me on social media and please support me by buying me a coffee☕ so I can upload more tutorials like this. See you in next post DEVs!