I get the following error when I try to run a database specific action within Django.

('42S02', "[42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'django_session'. (208) (SQLExecDirectW); [42S02] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)")

I must have missed a setting. By default, Django sends incorrectly formatted SQL command strings, here's two examples of wrong formats. First one is when I try to log into the admin portal:

SELECT TOP 1 (1) AS [a]
FROM [django_session]
WHERE [django_session].[session_key] = ?

And when I try to load data from table called dbo.Testing:

SELECT TOP 21 [TheAppName_testing].[id], [TheAppName_testing].[first_name], [TheAppName_testing].[last_name]
FROM [TheAppName_testing]
WHERE [TheAppName_testing].[id] = %s

I use different schema's for several tables. How do I go about pointing Django to the right settings so it can actually point to the correct tables within SQL Server?

1

There are 1 answers

0
rastawolf On

One simple method I've found to point to specific schemas using Django is to only give access to your desired schema to the user on the database side. Connect to the DB in Django's settings.py using that user, and when you migrate it will only be able to access the schema you want.