Multiple databases

Interacting with Multiple Databases

django-simple-history follows the Django conventions for interacting with multiple databases.

>>> # This will create a new historical record on the 'other' database.
>>> poll = Poll.objects.using('other').create(question='Question 1')

>>> # This will also create a new historical record on the 'other' database.
>>> poll.save(using='other')

When interacting with QuerySets, use using():

>>> # This will return a QuerySet from the 'other' database.
Poll.history.using('other').all()

When interacting with manager methods, use db_manager():

>>> # This will call a manager method on the 'other' database.
>>> poll.history.db_manager('other').as_of(datetime(2010, 10, 25, 18, 4, 0))

See the Django documentation for more information on how to interact with multiple databases.

Tracking User in a Separate Database

When using django-simple-history in app with multiple database, you may run into an issue where you want to track the history on a table that lives in a separate database to your user model. Since Django does not support cross-database relations, you will have to manually track the history_user using an explicit ID. The full documentation on this feature is in Manually Track User Model.