2013-06-11 3 views
2

내 프로젝트가 다중 데이터베이스를 사용하여 Auth, 컨텐츠 유형 정보 및 Project App를 관리하고 있습니다.Django의 ./manage.py syncdb를 실행할 때 update content_types 사용 안 함

내 데이터베이스 설정 :

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME': 'test_default', 
     'USER': 'root', 
     'PASSWORD': 'root', 
     'PORT': '', 
    }, 
    'auth_db': { 
     'ENGINE': 'django.db.backends.mysql', 
     'NAME': 'test_auth_db', 
     'USER': 'root', 
     'PASSWORD': 'root', 
     'HOST': '', 
     'PORT': '', 
    } 

나는 읽기 관리하고 내가 syncdb을 지금까지 모든 앱 콘텐츠 유형은 "auth_db"으로 업데이트받을 때

def db_for_read(self, model, **hints): 
    if model._meta.app_label == "auth" or model._meta.app_label == "sessions" or model._meta.app_label == "contenttypes": 
     return "auth_db" 
    return None 

def db_for_write(self, model, **hints): 
    if model._meta.app_label == "auth" or model._meta.app_label == "sessions" or model._meta.app_label == "contenttypes": 
     return "auth_db" 
    return None 

def allow_syncdb(self, db, model): 

    return True 

를 작성하는 라우터를 가지고있다. 이 작업을 중단하고 "기본"데이터베이스와 동기화하려고합니다. 모든 테이블은 기본 DB에서만 생성 및 업데이트됩니다.

프로젝트를 실행하면 라우터 구성에 따라 읽기 및 쓰기를 사용합니다.

어떻게 할 수 있습니까?

답변

1

나는 쓰기 funcfion

def db_for_write(self, model, **hints): 
    if model._meta.app_label in ("sessions",) : 
     return "auth_db" 
    return "default" 

그래서하여 syncdb는 "인증"와 "contenttypes"

에 데이터를 쓰지 않습니다 업데이트하여 고정
관련 문제