Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create HistoricalUser record on a separate database #538

Closed
dopatraman opened this issue Mar 25, 2019 · 3 comments
Closed

Unable to create HistoricalUser record on a separate database #538

dopatraman opened this issue Mar 25, 2019 · 3 comments

Comments

@dopatraman
Copy link
Contributor

Describe the bug
I have two databases, an operational and a history database. I've setup my db router such that all the historical tables get migrated onto the history database. However, commands that create operational models (users for instance) do not forward historical records to the history database. Instead, they attempt to lookup the history table in the operational database. This causes an error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/usr/local/lib/python3.7/site-packages/MySQLdb/cursors.py", line 312, in _query
    db.query(q)
  File "/usr/local/lib/python3.7/site-packages/MySQLdb/connections.py", line 224, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.ProgrammingError: (1146, "Table 'operational-db.operational-db_historicaluser' doesn't exist")

So far, I've initialized the HistoricalRecord instance like this:

history = HistoricalRecords(history_user_id_field=models.IntegerField(null=True), history_user_getter=_history_user_getter)

where my _history_user_getter is a function that accepts a historical_instance.

I assume there must be a way to configure the historical model to use a separate database. How do I do that?

To Reproduce
Steps to reproduce the behavior:

  1. Configure your dbrouter.py file to run a historicaluser migration on a separate database
  2. Run the migrations & verify the table has been created
  3. Attempt to create a superuser (python manage.py createsuperuser)
  4. Observe the error that appears

Expected behavior
I'd like to see a record in the historicaluser table (in the history database) that describes a user created in the operational database.

Environment (please complete the following information):

  • OS: Mac OSX Mojave
  • Django Simple History Version: 2.7.0
  • Django Version: 2.1
  • Database Version: MySQL
@rossmechanic
Copy link
Collaborator

Can you include a copy of the router that you're using? The functionality that you described should work.

@adamhaney
Copy link

@dopatraman I'm currently working to move my history models into a separate database and would love to see the router that you're using.

@rossmechanic
Copy link
Collaborator

Closed by #539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants