[Fixed]-Why does django's `apps.get_model()` return a `__fake__.MyModel` object


The fake objects are historical models. Here’s the explanation from Django docs:

When you run migrations, Django is working from historical versions of your models stored in the migration files.


Because it’s impossible to serialize arbitrary Python code, these historical models will not have any custom methods that you have defined. They will, however, have the same fields, relationships, managers (limited to those with use_in_migrations = True) and Meta options (also versioned, so they may be different from your current ones).

In case objects is a custom manager, you can set use_in_migrations = True to make it available in migrations.


Leave a comment