-
Notifications
You must be signed in to change notification settings - Fork 21
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
Schema not included in foreign keys in SQLAlchemy model #41
Comments
@leppikallio are you sure that it must be sa.ForeignKey("table2.id") ? without schema? and not sa.ForeignKey("schema2.table2.id")? |
@xnuinside, it has to be indeed in format sa.ForeignKey("schema2.table2.id"), in case schema_global = False. If schema_global = True the schema is essentially ignored "everywhere" if it exists in DDL and then also the FK has to be defined like sa.ForeignKey("table2.id")? |
@leppikallio I released 0.13.0 with your new feature ) and thanks for your impact and PR! If will be needed anything else - feel free to open new issue or PR |
Thank you so much! |
In a case where there are multiple schemas, schema name should be included in the generated foreign key references.
As an an example, a really simple dbdiagrams.io "model":
The exported PostgreSQL DDL looks like this:
Generating sqlalchemy model from this with command
creates model like this:
Problem is that the schema name is missing from sa.ForeignKey("table2.id"). This will fail because this statement would mean that the table should be found under "public" schema in postgresql, whereas the table is in fact in schema2.
Adding the schema reference like below fixes the issue:
The text was updated successfully, but these errors were encountered: