synchronization - Django Multiple Databases - One not always available -


i developing django application use multiple database backends. put sqlite database on machine running django application, , sync remote mysql database. tricky part machine running application not have internet connection, mysql database not availalble. there multiple machines running application, each it's own local sqlite db, using same remote mysql db.

i haven't written code yet, here have in mind. every time run insert or update write both databases, unless remote db unavailable, in case save sql statement in table on local database run when remote db available.

can done database routers, or need manually implement each db statement?

note on pk: not directly related, sure asked. primary key generated locally on each machine. in mysql db there field key, , field unique identifier each instance of application, provide unique key.

suppose have model called blog can use following store locally , remotely (assuming have configured access remote db).

blog = blog('test')  blog.save() #assuming sqlite default db try:     blog.save(using='mysql') except nointernetconnection:     pass 

make sure have defined , configured 'mysql' in settings.py , handle cases when there no internet connection.

side note: not quite sure why want this. if backup purposes use standard backup procedures. more information using multiple databases see: http://docs.djangoproject.com/en/dev/topics/db/multi-db/#using-raw-cursors-with-multiple-databases


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -