Reputation: 25
I want to write a multi-table application on Django, so I created two databases, one of them to use by default, other - "map" to use by specific app - "map".
map/models.py:
from django.db import models
class MapRouter(object):
def db_for_read(self, model, **hints):
if model._meta.app_label == 'map':
return 'map'
return None
def db_for_write(self, model, **hints):
if model._meta.app_label == 'map':
return 'map'
return None
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == 'map' or \
obj2._meta.app_label == 'map':
return True
return None
def allow_migrate(self, db, model):
if db == 'map':
return model._meta.app_label == 'map'
elif model._meta.app_label == 'map':
return False
return None
settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'eventmap',
'USER': 'eventmap',
'PASSWORD': 'eventmap',
'HOST': 'localhost',
'PORT': '',
},
'map': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'map',
'USER': 'eventmap',
'PASSWORD': 'eventmap',
'HOST': 'localhost',
'PORT': '',
}
}
DATABASE_ROUTERS = ['map.MapRouter']
The problem is when I run python manage.py syncdb
it says:
django.core.exceptions.ImproperlyConfigured: Module "map" does not define a "MapRouter" attribute/class
What's wrong with it?
Upvotes: 2
Views: 5239
Reputation: 599610
You need to put the full path to your router in the setting.
DATABASE_ROUTERS = ['map.models.MapRouter']
Upvotes: 5