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
This issue happens with SQLite. When I am adding a composite primary key using queryInterface.addConstraint() command, a foreign key check is performed using PRAGMA foreign_key_list(tableName).
However, the query fails when tableName is hyphenated. Ideally, any table should be accepted but it is not in this case unless I change my table name.
Table should be created with a composite primary key.
What is actually happening?
An error was shown indicating this :
SQL command PRAGMA foreign_key_list(calendar-list) fails. Error in the syntax near -
Additional context
I understand the error because the command used is incorrect. It should be PRAGMA foreign_key_list('calendar-list'). Sequelize should add quotes to table names when performing foreign key check with SQLite.
I checked SQLite documentation and PRAGMA foreign_key_list('tableName') should work as it is a valid command.
/** * Generates an SQL query that returns all foreign keys of a table. * * @param {string} tableName The name of the table. * @returns {string} The generated sql query. * @private */getForeignKeysQuery(tableName){return`PRAGMA foreign_key_list(${tableName})`;}
${tableName} should be in quotes '${tableName}'.
This should satisfy all scenarios for table names and shouldn't cause an issue.
Environment
Sequelize version: 4.x.x, 5.x.x and 6.x.x
Node.js version: 14.16.0
Operating System: MacOs Catalina 10.15.17
Issue Template Checklist
How does this problem relate to dialects?
I think this problem happens only for the following dialect(s): sqlite
Would you be willing to resolve this issue by submitting a Pull Request?
Yes, I have the time and I know how to start.
The text was updated successfully, but these errors were encountered:
Issue Description
This issue happens with SQLite. When I am adding a composite primary key using
queryInterface.addConstraint()
command, a foreign key check is performed usingPRAGMA foreign_key_list(tableName)
.However, the query fails when tableName is hyphenated. Ideally, any table should be accepted but it is not in this case unless I change my table name.
What are you doing?
What do you expect to happen?
What is actually happening?
An error was shown indicating this :
Additional context
I understand the error because the command used is incorrect. It should be
PRAGMA foreign_key_list('calendar-list')
. Sequelize should add quotes to table names when performing foreign key check with SQLite.I checked SQLite documentation and
PRAGMA foreign_key_list('tableName')
should work as it is a valid command.I found the culprit here https://github.com/sequelize/sequelize/blob/v5/lib/dialects/sqlite/query-generator.js
${tableName}
should be in quotes'${tableName}'
.This should satisfy all scenarios for table names and shouldn't cause an issue.
Environment
Issue Template Checklist
How does this problem relate to dialects?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: