How to change db from sqlite to postgresql?

My project is built on sqlite django db and now, I want to change database to postgresql for production. Please can someone tell me who to approach this? I have seen codes about this but not confident to just implement and then get issues.

Thanks

There are two parts to this:

  1. Getting your system running on Postgresql
  2. Migrating any existing data from sqlite to your Postgresql database.

#1 is easy.

  • Create your database
  • Create the role you’re going to use
  • Change your DATABASE settings
  • Run a migrate command to create your tables

Any problems that might show up will show up here.

#2 could be where you have problems, but again, they should show up quickly - it’s not like you’re going to make this change and run it for days before the problems appear.
Depending upon what dependencies your data may have on system tables (such as ContentType) or if you’re using any non-standard data types, this could be as simple as using dumpdata on your sqlite data and then using loaddata to add it to your Postgresql database. Or, you might need to write some conversion routines to make this work. Either way, this isn’t a question that can be answered without knowing a lot more about the application and the data being migrated.

(Note: I’ve gone through this process twice myself. It’s really not that hard.)

Ken

1 Like