1

The goal

I want Doccano to use the users that are saved in my main app (app2) as its own users, instead of Doccano using its own users. These are both Django databases, so i assume these are not Doccano specific issues

The problem

The connection between the users work, I can login into Doccano with app2 users. when in the /projects page an 500 internal server error arises on the website and inn the terminal app2 prints: ERROR: relation "api_project" does not exist at character 363

When creating a new project a 403 Forbidden arises when doing a POST to /v1/projects

What I did

I am currently running the Doccano Backend, nginx and postgres in their containers and running app2 and the postgres_app2 in containers as well. Doccano backend shares a (docker-compose)network with Doccano postgres and another network with postgres_app2. doccano/app/app/settings.py has both databases and a link to the router:

# settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': path.join(BASE_DIR, 'db.sqlite3'),
    },
    "app2_db": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "postgres",
        "USER": os.getenv("POSTGRES_USER", "user_app2"),
        "PASSWORD": os.getenv("POSTGRES_PASSWORD", "pass_app2"),
        "HOST": "postgres",
        "PORT": 5432,
    }
}

DATABASE_ROUTERS = ['app.authRouter.AuthRouter']

with the AuthRouter.py looking like this:

# AuthRouter.py

class AuthRouter(object):
    def db_for_read(self, model, **hints):
        if model._meta.app_label == 'auth' or model._meta.app_label == 'authtoken':
            return 'app2_db'
        return None

    def db_for_write(self, model, **hints):
        if model._meta.app_label == 'auth' or model._meta.app_label == 'authtoken':
            return 'app2_db'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        if obj1._meta.app_label == 'auth' or obj1._meta.app_label == 'authtoken' or \
           obj2._meta.app_label == 'auth' or obj2._meta.app_label == 'authtoken':
           return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        if app_label == 'auth' or app_label == 'authtoken':
            return db == 'app2_db'
        return None
louis_guitton
  • 5,105
  • 1
  • 31
  • 33
moniek
  • 17
  • 2

0 Answers0