I have mssql database with few tables:
[dbo].[one_table]
[dbo].[two_table]
[model].[three_table]
[model].[four_table]
[plan].[five_table]
my django settings.py:
DATABASES = {
'default': {
"ENGINE": "mssql",
"NAME": "ips_db",
"USER": "sa",
"PASSWORD": "***",
"HOST": "***",
"PORT": "1433",
"OPTIONS": {
"driver": "ODBC Driver 17 for SQL Server",
},
},
}
When i try inspect db by
python inspectdb > models.py
I get only one_table
and two_table
class One_table(models.Model):
firstname = models.CharField(db_column='FirstName', max_length=30, db_collation='SQL_Latin1_General_CP1_CI_AS') # Field name made lowercase.
lastname = models.CharField(db_column='LastName', max_length=40, db_collation='SQL_Latin1_General_CP1_CI_AS') # Field name made lowercase.
class Meta:
managed = False
db_table = 'One_table'
class Two_table(models.Model):
test = models.CharField(db_column='Test', max_length=10, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True) # Field name made lowercase.
tes2 = models.CharField(db_column='Tes2', max_length=10, db_collation='SQL_Latin1_General_CP1_CI_AS', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'Two_table'
How can i get all tables models from my database???
CodePudding user response:
I haven’t this problem. Just write each table by comma separated
CodePudding user response:
I was looking at mssql\introspection.py. There is Databaseintrospection.get_table_list(). Sql query in this method is
sql = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ' "'" get_schema_name() "'"
and i look at the get_schema_name()
and...
that is
def get_schema_name():
return getattr(settings, 'SCHEMA_TO_INSPECT', 'dbo')
Cause i just delete WHERE TABLE_SCHEMA"
and get all my tables.
This looks like very strange. I can`t choose schema.