Wrong table name when using abstract models
See original GitHub issueHello people,
What’s the expected table name for a history model when I’m using an abstract model like this?
# core/models.py
class HistoryMixin(models.Model):
history = HistoricalRecords(inherit=True)
class Meta:
abstract = True
class SameModuleModel(HistoryMixin, models.Model):
pass
# app1/models.py
class AnotherAppModel(HistoryMixin, models.Model):
pass
In this example, the makemigrations
output is:
Migrations for 'core':
0001_initial.py:
- Create model HistoricalAnotherAppModel
- Create model HistoricalSameModuleModel
- Create model SameModuleModel
Migrations for 'app1':
0001_initial.py:
- Create model AnotherAppModel
All models that inherit from HistoryMixin
will have its history db table named like core_historicalmodel_name
and not like model_module_using_HistoryMixin_historicalmodel_name
.
Am I not seeing something here?
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Wrong table name when using abstract models #224 - GitHub
Hello people, What's the expected table name for a history model when I'm using an abstract model like this? # core/models.py class ...
Read more >Laravel assumes wrong table name in model when it is hard ...
Question: Could someone explain to me why Laravel is pointing to the 'products' table (a real table i have) and not the explicitly...
Read more >Using abstract models in Django - DEV Community
It is important to keep in mind that abstract models by themselves are quite useless. There is no database table created for them...
Read more >Best practices working with Django models in Python - SteelKiwi
Here we go: 1. Correct Model Naming. It is generally recommended to use singular nouns for model naming, for example: User , Post...
Read more >Modeling Polymorphism in Django With Python
The abstract base model Product only exists in the code, so there is no products table in the database. The Django ORM will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue is fixed in #324 with tests
@rougeth: This looks like an edge case that was missed when the feature was added. I’ll look at patching it.
Several people asked for the feature, so even though I don’t use it myself I put some code together that would make it work, and asked for testing in addition to the unit tests I added, but I guess it was missed.
Hopefully having the table names changed won’t cause too many issues for people already using the feature.