question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong table name when using abstract models

See original GitHub issue

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 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:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rossmechaniccommented, Mar 23, 2018

This issue is fixed in #324 with tests

2reactions
macro1commented, Jul 9, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found