[Solved]-Exclude an app from Django migrations

8👍

Removing the __init__.py file from within the apps migrations directory should work.

👤audeos

8👍

remove the app from installed apps in your settings.

0👍

You can do this if you use database routers with

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

Example.

class FilemakerRouter:
    """
    A router to control all database operations on models in the
    filemaker application.
    """
    def db_for_read(self, model, **hints):
        """
        Attempts to read filemaker models go to filemaker.
        """
        if model._meta.app_label == 'filemaker':
            return 'filemaker'
        return None

    def db_for_write(self, model, **hints):
        """
        Attempts to write filemaker models go to filemaker.
        """
        if model._meta.app_label == 'filemaker':
            return 'filemaker'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the filemaker app is involved.
        """
        if obj1._meta.app_label == 'filemaker' or \
           obj2._meta.app_label == 'filemaker':
           return True
        return None

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

Search duckduckgo for more details

Leave a comment