我正在使用 typescript 和 Sequelize ,我有以下表格:Prophet、模型和任务,它们都有一个 n :m 彼此之间的关系,因此sequelize会自动创建另外3个表:modelProphets、modelTasks和prophetTasks。 我为它们每个人都有一个简单的存储库,并且模型和任务在存储库中具有额外的功能:
public findWithoutProphet(): Promise<any> {
const query = `SELECT models.name FROM models WHERE NOT EXISTS
(SELECT modelProphets.modelName FROM modelProphets WHERE models.name = modelProphets.modelName);`;
return this.database.rawQuery(query);
}
我对每个存储库功能进行单元测试,但问题是,当我使用sequelize方言“sqlite”运行时,一切正常,但如果我将其更改为本地docker postgres并再次运行它,则在运行期间会抛出错误该查询说“modelProphets”不存在(如果我先运行任务而不是模型,则不存在prophetTasks)。所有其他存储库功能,如创建、删除、更新、查找,一切正常。我什至使用 pgAdmin4 检查了数据库,所有关系表都在那里,所以...
为什么当 sqlite 运行良好时,sequelize 会给我这个 postgresql 错误?每个数据库的自动关系表是否不同?我应该为每个正在测试的数据库使用不同的存储库吗?
最佳答案
我没怎么使用过sequelize,但是Postgres 不能很好地处理大写字母。如果您希望 Postgres 保留名称的大小写,请将表名称放入双引号中。
Quoting an identifier also makes it case-sensitive, whereas unquoted names are always folded to lower case. For example, the identifiers FOO, foo, and "foo" are considered the same by PostgreSQL, but "Foo" and "FOO" are different from these three and each other. (The folding of unquoted names to lower case in PostgreSQL is incompatible with the SQL standard, which says that unquoted names should be folded to upper case. Thus, foo should be equivalent to "FOO" not "foo" according to the standard. If you want to write portable applications you are advised to always quote a particular name or never quote it.)
来自 docs
关于javascript - 找不到 Sequelize n :m relation tables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52766868/