Using RedShift as an Additional Django Database

I have two Databases default, which is a regular MySQL backend and redshift(using the backend postgres). I would like to use RedShift as a read-only database, which is used only for django-sql-explorer .

Here is the router I created in my_project/common/routers.py:

class CustomRouter(object):
    def db_for_read(self, model, **hints):
        return 'default'

    def db_for_write(self, model, **hints):
        return 'default'

    def allow_relation(self, obj1, obj2, **hints):
        db_list = ('default', )
        if obj1._state.db in db_list and obj2._state.db in db_list:
            return True
        return None

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

And mine settings.pyrefers to it like this:

DATABASE_ROUTERS = ['my_project.common.routers.CustomRouter', ]  

The problem occurs when called makemigrations, Django throws an error indicating that it is trying to create tables django_*in RedShift (and, obviously, does not work because the postgres type is serialnot supported by RedShift:

...
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (Column "django_migrations.id" has unsupported type "serial".)

So my question is twofold:

  • Is it possible to completely disable Django management for the database, but still use ORM?
  • , Django ?

,

- Column 'django_migrations.id' 'serial' [ Amazon Redshift]

+4
1

, . PR, : https://github.com/django/django/pull/7194

, :

  • . . allow_migrate() return False .
  • Django >= 1.10.4, , . , - , Read-Replica.
+4

Source: https://habr.com/ru/post/1662432/


All Articles