[Django]-Django-pyodbc-azure – How to use schemas

5👍

IIRC, you need to change the default schema for the user your are connecting as. If you’re using a SQL Auth user called django_user:

ALTER USER django_user WITH DEFAULT_SCHEMA = [sp]

Good luck.

3👍

Define the db_table under the Meta class of one model as follows:

db_table = "[your_schema].[your_table]"

2👍

I’ve found that a number of answers don’t seem to work any more. Instead, I use the instructions found here to set the schema when defining db_table such as it goes schema].[table. Don’t open those square brackets; the important bit is the ].[ between schema and table name.

In your case, you’d need to set:

class Meta:
    managed = False
    db_table = 'sp].[tablename'

Leave a comment