-
-
Notifications
You must be signed in to change notification settings - Fork 478
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
Error when setting table_name with inherit=True #1195
Comments
muneeb706
changed the title
db_table is used by multiple models error when setting table_name with inherit=True
Error when setting table_name with inherit=True
Jun 24, 2023
muneeb706
added a commit
to muneeb706/django-simple-history
that referenced
this issue
Jun 24, 2023
Error was thrown when table_name is set with inherit=True in base model. - add not inherited check jazzband#1195
11 tasks
This was referenced Jun 24, 2023
ddabble
added a commit
that referenced
this issue
Aug 15, 2023
* fix(simple_histor.models): Custom history table name Error was thrown when table_name is set with inherit=True in base model. - add not inherited check #1195 * fix(docs): Custom history table name - authors and changes docs updated * merge(master): Merged latest changes from master * merge(master): Resolved conflicts * merge(master): Resolved conflicts * merge(master): Resolved conflicts * merge(master): Resolved conflicts * fix(simple_histor.models): Custom history table name - unit test added * Small improvement of the test for #1196 Now also compares the table name of the inherited (base) model, so that it's easier to see that the history table name is not inherited. * Added note on table_name inheritance to docs --------- Co-authored-by: Anders <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem Statement
When
table_name
is set withinherit=True
in base model then error is thrown whenmakemigrations
command is entered.For example:
Following error is thrown with above code:
(models.E028) db_table 'base_model_history' is used by multiple models: inherit.HistoricalBaseModel, inherit.HistoricalChildModel.
Describe the solution you'd like
Cause of Problem
As per my understanding, after looking at the source code, I found that
Meta.db_table
property of model is updated whentable_name
property is set. In case, wheninherit=True
,self.table_name
still points totable_name
set in the base model whencreate_history_model
method is invoked for the child model. This logic is implemented in line 301-302 in create_history_model method.Possible Solution
inherited flag is sent as an argument to
create_history_model
method, this can be used in the condition where table_name is checked. Condition at line 301 will look like this:if not inherited and self.table_name is not None:
If it can not be done, then this behavior should be mentioned explicitly in the documentation.
Describe alternatives you've considered
Overridden
create_history_model
method to updatetable_name
when inherited is set to True and table_name is set:Additional context
I found this issue while looking for the solution of #1174
The text was updated successfully, but these errors were encountered: