ravioli
ravioli

Reputation: 3833

Django - global setting to specify all models as non-managed

I'm writing a Django app, but have a separate process for creating / managing the tables. In other words, I don't want Django to manage any of the DB tables. To accomplish this, I use managed = False in the Meta class, like:

class School(models.Model):
    
    schoolid = models.IntegerField(primary_key=True)
    schooldisplayname = models.CharField(max_length=100)
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=100)
    department = models.CharField(max_length=100)

    class Meta:
        managed = False

But it's annoying to have to always specify this for each model. Is there a way to apply this as a global setting to all my models by default? Danke.

Upvotes: -1

Views: 454

Answers (2)

Vishnu Kiran
Vishnu Kiran

Reputation: 652

While I am not sure if a global way exists if you are looking for a quick way to mark managed=False for your existing models. You can do this.

python manage.py inspectdb > yourapp/models.py

You get managed = False in every model class by default.

Upvotes: 1

kevswanberg
kevswanberg

Reputation: 2119

I'm not quite sure how to do exactly this. It might be better to mark them all as managed = false so it's explicit.

You can disable migrations globally in settings. Not quite the same...

from settings import *

class DisableMigrations(object):
    def __contains__(self, item):
        return True

    def __getitem__(self, item):
        return 'notmigrations'

MIGRATION_MODULES = DisableMigrations()

Upvotes: 1

Related Questions