小编Nad*_*ari的帖子

为什么django_migrations表在所有数据库中

我建立一个网站下Django框架,这个网站需要有不同的SQL计划,现在我成功创建的所有计划和所有的东西,但我不明白为什么表django_migrations是在数据库迁移后每个模式.

  • 预期数据库内容:

    AppDB表是此应用程序定义的所有模型

    默认数据库表都是Django表(admin,contenttypes,auth,sessions)

  • 数据库内容:

    AppDB表是此app + django_migrations定义的所有模型

    DEFAULT表都是Django表(admin,contenttypes,auth,sessions)+ django_migrations

这些是2 dbs的路由器:

class DefaultRouter(object):
    APPS = ['auth', 'sessions', 'admin', 'contenttypes']
    DB = 'default'

    def db_for_read(self, model, **hints):
        if model._meta.app_label in self.APPS:
            return self.DB
        return None

    def db_for_write(self, model, **hints):

        if model._meta.app_label in self.APPS:
            return self.DB

        return None

    def allow_relation(self, obj1, obj2, **hints):

        if obj1._meta.app_label in self.APPS or obj2._meta.app_label in self.APPS:
            return True
        return None

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

        if app_label in self.APPS:
            return db == self.DB
        return None …
Run Code Online (Sandbox Code Playgroud)

python django configuration database-migration multiple-databases

7
推荐指数
1
解决办法
3359
查看次数