You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
missing schema name in generated SQL for foreign keys #2464
Notice: I'm using PostgreSQL with schemas, and sequelizer 2.0-rc2
I've got a small problem trying sequelize do all magic with my relations.
I want to create relationship n:m, but I also want that transition table to have few additional fields.
I've defined model with explicit foreign keys (where references are pointing to model instance) - something like this:
But when I try to create schema I've got this SQL - which do not have schema names in references bits:
CREATETABLEIF NOT EXISTS "configuration"."company_views" (
"sort_order"INTEGER,
"company_code"VARCHAR(255) REFERENCES"companies" ("code"), -- look ma' - no schema"view_code"VARCHAR(255) REFERENCES"views" ("code"), -- look ma' - no schema"created_at"TIMESTAMP WITH TIME ZONENOT NULL,
"updated_at"TIMESTAMP WITH TIME ZONENOT NULL,
PRIMARY KEY ("company_code","view_code")
);
Changing definition to something like this also doesn't work:
changed the title [-][bug] missing schema name in generated SQL for foreign keys[/-][+]missing schema name in generated SQL for foreign keys[/+]on Oct 22, 2014
Activity
[-][bug] missing schema name in generated SQL for foreign keys[/-][+]missing schema name in generated SQL for foreign keys[/+]setthase commentedon Oct 23, 2014
I think I found a solution to this issue! We need to change this lines :
to look like this:
janmeier commentedon Oct 23, 2014
Yep, that sounds plausible. Feel free to provide a PR with that code + test :)
setthase commentedon Oct 23, 2014
Maybe we should grep source to find all
.tableNameand change it to.getTableName()?mickhansen commentedon Oct 23, 2014
@codename- not a bad idea, in general it should be using
getTableName()since that handles the schema stuff as you figured out.mickhansen commentedon Oct 23, 2014
@janmeier kinda strange we change the tablename in the model, that should probably not happen untill SQL generation, oh well :p
janmeier commentedon Oct 23, 2014
Yeah doing it in query generation would probably be cleaner :)
iamjoyce commentedon Aug 31, 2016
This issue also exists for MSSQL. The fix suggested by @codename- does solve the problem.
felixfbecker commentedon Aug 31, 2016
@iamjoyce PR welcome!
fix(model/init): add schema name to foreign key when generating creat…
fix(model/init): add schema name to foreign key when generating sql s…
fix(model/init): add schema name to foreign key when generating sql s…