I created a Django application and connected it to SQL Server with a trusted connection. When I migrate, Django is creating a new schema name (trusted connection username) in the database and adding this on all tables as prefix. By my IT department convention, all tables should be created with the 'dbo' prefix.
The most interesting part is: When I access the database from SSMS (also with trusted connection), and create a new database, I do not have this issue, it creates as 'dbo.table_name'.
Does anybody knows how can I fix it? See below better example and some code.
Summary:
Django creating: 'my_username.table_name'
I need: 'dbo.table_name'
My django settings.py
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'dabase_name',
'HOST': 'database_host',
'USER': '',
'OPTIONS': {
'driver': "ODBC Driver 17 for SQL Server",
'Trusted_Connection' : 'Yes',
}
}
}
One of my models (table) as example:
class Sap_module(models.Model):
sap_module = models.CharField(max_length=2, unique=True)
available = models.BooleanField(default=True)
def __str__(self):
return self.sap_module