Django Raw SQL relation does not exists

I am trying to execute raw sql but it requires a relation and I am not really sure where and why it doesnt work as it should.

Settings.py

    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'Primary', 
        'USER': 'user', 
        'PASSWORD': 'password',
        'HOST': 'host', 
        'PORT': '5433',
    },
    'DataDB': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'SpecialDataDB', 
        'USER': 'user', 
        'PASSWORD': 'password',
        'HOST': 'host', 
        'PORT': '5433',
    }
}

getData.py

    
    if request.GET['data'] == True:
        with connections['DataDB'].cursor() as cursor:
            cursor.execute("Select i from Test")
            row = cursor.fetchone()
            return cursor
    return None

I have no problem connecting to first database and use my user to authenticate, then I am trying to grab data from 2nd database (that should be read only) and I get error:

relation "test" does not exist LINE 1: Select i from Test

2nd Database is only for read, why not DBRouter? I've created it before and it didnt work as intended.

All I want to do now is get that raw data and return it to the view.

On the other hand I can create table using raw query.

cursor.execute("CREATE TABLE IF NOT EXISTS test (i integer)")

^ that works

How should I write select query to get the data without creating a model or how to create the model that's gonna work with it?

Back to Top