#34188 closed Uncategorized (wontfix)

Add a section on refresh_from_db to the Multiple databases documentation

Reported by: martinmain93 Owned by: Leo Tom
Component: Documentation Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

I've recently implemented multiple databases in a project using a read-replica setup, and everything went quite smoothly. The docs ( https://docs.djangoproject.com/en/4.1/topics/db/multi-db/) were helpful to set up a simple database router and the appropriate config changes. One of the first big issues I ran into was that I quickly ran into errors any time in the app that refresh_from_db was being used. Because of the nature of the command, it's usually being issued when some action was committed and I want to get the latest data from the database. Of course this is going to be an issue with multiple databases. With some digging, I discovered that you can indeed use refresh_from_db(using=db) to select the default database. This quickly solved the issue.

I think it would be very useful to anyone setting up a multi db setup to have a short section on the Multiple Databases docs that includes this information.

Change History (2)

comment:1 by Leo Tom, 17 months ago

Owner: changed from nobody to Leo Tom
Status: newassigned

comment:2 by Carlton Gibson, 17 months ago

Resolution: wontfix
Status: assignedclosed

I think this is already covered by the note in the refresh_from_db docs:

The reloading happens from the database the instance was loaded from, or from the default database if the instance wasn’t loaded from the database. The using argument can be used to force the database used for reloading.

Note: See TracTickets for help on using tickets.
Back to Top