Closed leppikallio closed 1 year ago
@leppikallio are you sure that it must be sa.ForeignKey("table2.id") ? without schema? and not sa.ForeignKey("schema2.table2.id")?
@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: