0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

basically i would have to add a DB connection to my settings and it would replicate there... Doesn't django offer any kind of support for this stuff? btw i would need the seccond DB on a remote server
Django has no support for this kind of syncronization. I would suggest you having a copy of database using replications (mechanism of db itself). From my prospective Django have multi-db feature for reason of using one db for read other for write (for example if you have some old system and need to create some kind of glue app in between). Also read a warning about content-types on the bottom: docs.djangoproject.com/en/dev/topics/db/multi-db

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.