【问题标题】:Disable update content_types when running Django's ./manage.py syncdb运行 Django 的 ./manage.py syncdb 时禁用更新 content_types
【发布时间】:2013-06-06 23:57:38
【问题描述】:

我的项目正在使用 Multiple Data Base 来管理 Auth 、内容类型信息和 Project App。

我的数据库设置:

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': '',
    }

我有一个路由器来管理读写

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 

每当我执行 syncdb 时,所有应用内容类型都会在“auth_db”中更新。我想停止这个并与“默认”数据库同步。这样所有表将仅在默认数据库中创建和更新。

当项目运行时,它将根据路由器配置使用读写。

我该怎么做?

【问题讨论】:

    标签: python django


    【解决方案1】:

    我通过更新写入函数来修复它

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

    所以syncdb不会向“auth”和“contenttypes”写入任何数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-17
      • 2011-01-20
      • 1970-01-01
      • 2015-04-25
      • 2010-11-30
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      相关资源
      最近更新 更多