javascript - 找不到 Sequelize n :m relation tables

标签 javascript postgresql typescript sqlite sequelize.js

我正在使用 typescript 和 Sequelize ,我有以下表格:Prophet模型任务,它们都有一个 n :m 彼此之间的关系,因此sequelize会自动创建另外3个表:modelProphetsmodelTask​​sprophetTasks。 我为它们每个人都有一个简单的存储库,并且模型和任务在存储库中具有额外的功能:

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/

相关文章:

sql - 如何在 PostgreSQL 中测试运行 UPDATE 语句?

mysql - 使用 doctrine 2 在 Postgres 中选择模式配置

angular - 使用 Angular $interval 按时间间隔更新 TextView

javascript - 抛出新的类型错误 ('Invalid argument type' );来自 {mypath}\Desktop\reddit\node_modules\@redis\client\dist\lib\client\RESP2\encoder.js :17 t

javascript - 在 JavaScript 中使用循环传递哈希表/字典

javascript - 桌面小部件使用的 $.getJSON 不从浏览器请求 URL

javascript - 如何设置 String#replace 回调的参数?

postgresql - postgresql/Vacuum 中大量的活/死元组不起作用

javascript - 使用 Typescript 时,如何创建类装饰器以将新方法混合到 React 组件中?

javascript - 从 WebdriverIO 中的基本 pageobject 页面调用方法时出现 "is not a function"错误