5👍
The short answer is that Django is not built for this. Making your model “unmanaged” only means Django will not create or delete the table for it — nothing else.
That said, if you have no regular models alongside these dynamic models in the same app, you can conditionally add the app to INSTALLED_APPS
in settings.py
:
if not ('makemigrations' in sys.argv or 'migrate' in sys.argv):
INSTALLED_APPS += (
'app_with_dynamic_models',
'another_app_with_dynamic_models',
)
This should make Django ignore the app when creating and running migrations. However, you will eventually have to make and run migrations for the models if you want to use them, since the ability to have apps which do not use migrations is meant to go away in Django 1.9. Could your dynamic models be refactored to use the contenttypes framework?
3👍
I suggest you replace the generated migrations.CreateModel
operation by one of your own that always reflect the actual model state. This way no state changes should be ever detected.
class CreateDynamicModel(CreateModel):
def __init__(self):
# ... dynamically generate the name, fields, options and bases
super(CreateDynamicModel, self).super(
name=name, fields=fields, options=optins, bases=bases
)
- [Django]-Django – getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-How can I find the union of two Django querysets?
- [Django]-Django: Model Form "object has no attribute 'cleaned_data'"
1👍
You can probably write a custom database router with the allow_migrate method returning False
for your dynamic models. The migrate
command will disallow them in that case.
As long as you don’t load these dynamic models in any models.py
module, makemigrations
shouldn’t pick them up either.
- [Django]-Serving large files ( with high loads ) in Django
- [Django]-Indexing JSONField in Django PostgreSQL
- [Django]-How to get username from Django Rest Framework JWT token