Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is only the default schema inspected when running inspectdb #104

Open
lukasburg opened this issue Feb 11, 2021 · 2 comments
Open

Why is only the default schema inspected when running inspectdb #104

lukasburg opened this issue Feb 11, 2021 · 2 comments

Comments

@lukasburg
Copy link

Disclaimer: this might be a really stupid question, I actually know very little about schemas and mssql.

I am running python manage.py inspectdb on a mssql database that contains multiple schemas.
These are a way of separating topics inside the db (I think?).
E.g. there might be a schema called users that contains the tables users.User, users.Post, users.Friendships and a second schema called games that contains other tables.

When I run inspectdb the output is empty because there are no tables in the main scheme dbo.

I changed

sql = 'SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = SCHEMA_NAME()'
to

sql = "SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES;"

and now all tables are created. Only the schemes names are not displayed correctly in db_table. It says 'User' instead of 'users.User', but that's fixed fast.

So my question: Why did you choose to only inspect tables in dbo? Did I miss something in the settings? Is creating multiple schemes something very unusual?

@timnyborg
Copy link

timnyborg commented Feb 14, 2021

A small note: it inspects whichever schema is set as the user's default schema (which is normally dbo). I have a db with two schemas that I wanted to generate models for, so I just switched my test user's default schema to each of them before running inspectdb.

Django does not natively support schemas, which is really too bad. db_table = '[schema].[tablename]' works pretty well, but will run into trouble if you ever want Django to manage your table.

@lukasburg
Copy link
Author

@timnyborg Thanks for the quick response and explanation!

I havn't tried to let django manage the tables, so I overlooked that completely obvious explanation.

Should I close this issue? Don't know if working with schemas is really an important feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants