Django: prevent making migrations for some models

Viewed 232

Django 3.2.6

I'd like some models not to made migrations at all.

Is it possible?

I tried:

1. https://docs.djangoproject.com/en/3.2/ref/models/options/#managed

class Meta: managed = False

2.

 class PrimaryReplicaRouter:
     special_model_names = {'generalsettings', 'generalsettings', }

     def allow_migrate(self, db, app_label, model_name=None, **hints):
         if model_name in self.special_model_names:
             return False

         return True

It doesn't help: migrations are created.It doesn't migrate. But migrations become unnecessarily noisy.

I quote from here:

https://docs.djangoproject.com/en/3.2/topics/db/multi-db/#allow_migrate

makemigrations always creates migrations for model changes, but if allow_migrate() returns False, any migration operations for the model_name will be silently skipped when running migrate on the db.

Well, I don't want to make migrations for some models. Is it possible?

1 Answers
Related