I've got a Django app called dataapi
which is built by introspecting a PostgreSQL database to write various models files (one for each schema). It works and provides us read-only access to the data we need via the ORM, but I break up models into multiple files by schema rather than putting them all in a (huge) models.py file.
I've defined a ROOT/config/routers.py
file tell Django I don't want this app's models to use migrations:
class DataAPIRouter(object):
"""
A router to control all database operations on models in the
dataapi application.
"""
def db_for_read(self, model, **hints):
"""
Attempts to read dataapi models go to mssqlwrds.
"""
if model._meta.app_label == 'dataapi':
return 'pgdata'
return None
def db_for_write(self, model, **hints):
"""
Attempts to write dataapi models go to mssqlwrds.
"""
if model._meta.app_label == 'dataapi':
return 'pgdata'
return None
def allow_relation(self, obj1, obj2, **hints):
"""
Allow relations if a model in the dataapi app is involved.
"""
if obj1._meta.app_label == 'dataapi' or obj2._meta.app_label == 'dataapi':
return True
return None
def allow_migrate(self, db, app_label, model_name=None, **hints):
"""
Make sure the dataapi app doesn't use migrations.
"""
if app_label == 'dataapi':
return False
return True
In my settings, I've defined the router:
DATABASE_ROUTERS = [
'config.routers.DataAPIRouter',
]
Yet when I run a dry run using makemigrations
, it still shows that it's hitting the app:
(project) [vagrant@vagrant project]$ ./manage.py makemigrations --dry-run
Migrations for 'dataapi':
0001_initial.py:
- Create model aco_amda
- Create model aco_imda
- Create model aco_indfnta
- Create model aco_indfntq
[...]
Am I missing something? How can I get this app to be ignored by migrations?