pedrotorres
pedrotorres

Reputation: 1232

Django Multiple Databases

I am trying to implement a Django project with two databases. The seccond one would basically be a backup in case anything happens. So I just want my code to save everything to both db's and read from the default one.

I tried to use routers but it just gives one to write. So I added in every model a line to save in both DB's. MY problem now is Django auth User, which I can't override it's save function. I tried using save(using="second_db") but it throws exceptions saying theres already an user with that username.

Any ideas how this should work?

Upvotes: 0

Views: 128

Answers (1)

nickzam
nickzam

Reputation: 813

You can use database replication. Mysql and postgresql are capable of doing that. Read on master-slave replication. http://www.postgresql.org/docs/9.2/static/high-availability.html

Doubling data on application level is overhead. What if you decide to add 3rd database for any reason? So you will need to alter your code to support that third database.

Upvotes: 1

Related Questions