I have to read an existing SQL-SERVER database with Django FWK and after connecting succesfully to the DB, when I refer to MyModel.objects.all() Django launch a query with the table name quoted, but it fails because SQL-Server needs the prefix schema, getting the error:
('42S02', "[42S02] [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'table_name'. (208) (SQLExecDirectW)")
EDIT: This only happens with a non 'default' django database settings. Misteriously, my default database doesn't need any special treatment, and is a sql-server database with a db user without default schema.
How can I configure the model or the settings.DATABASE or the dbrouter to make django connect to the specific schema and don't need to use the schema_name?
Option 1: model Meta class property: db_table = 'schema_name.table_name' doesn't work, because the query that builds has the FROM clause as [schema_name.table_name] and what sql needs is [schema_name].[table_name]
Option 2: settings.DATABASE 'NAME' already refers to the schema_name, but it's not enough
Option 3: no idea how to tell django to connect to the specific schema or to add the prefix schema name to all the queries it builds.
Option 4: make django do not surround db_table with brackets. When I define db_table as 'schema.table' the resulting query surround this with [schema.table]. Without "[]" brackets query would work.