loopbackio / loopbackio/loopback-connector-postgresql
Error in your foreign key creations instructions page.
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 118
- 派生
- 184
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 5
描述
https://loopback.io/doc/en/lb4/todo-list-tutorial-sqldb.html#specify-the-foreign-key-constraints-in-todo-model
In your example below.
@model({
settings: {
foreignKeys: {
fk_todo_todoListId: {
name: 'fk_todo_todoListId',
entity: 'TodoList',
entityKey: 'id',
foreignKey: 'todoListId',
},
},
},
})
export class Todo extends Entity {
//etc.
}
When following the setup above to run database migration for my local postgresdb as part of todo example tutorial, I encountered the following error:
Cannot migrate database schema error: column "todoListId" referenced in foreign key constraint does not exist
at Parser.parseErrorMessage (/Users/andywongcheeming/Projects/poc/todo-list/node_modules/pg-protocol/dist/parser.js:283:98)
I was left puzzled why the instructions did not work as expected. I dig up online and my personal ChatGPT to understand if Postgres DB has case-sensitive when comes to table and field naming conventions. It turns out that it does.
When I go back and check my local postgres todo definitions via psql cli.
todo_db=# \d todo
Table "public.todo"
Column | Type | Collation | Nullable | Default
------------+---------+-----------+----------+---------
id | integer | | not null |
title | text | | not null |
desc | text | | |
iscomplete | boolean | | |
todolistid | integer | | |
It turns our the foreign key todolistid comes out as lower case by default when running Loopback db migration tool. The sample @model code above supplied as {foreignKey: 'todoListId'}.
I corrected it to use lower-case, dropped the database and started the migration all over again. The migration works this time.
Thus, I must ask - shouldn't the instructions be updated to use lowercase since the plugin creates tables and field names in lowercase by default?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 LoopBack Todo 列表 SQL 数据库教程中链接的外键部分开始,将其 foreignKey 值与迁移生成的 PostgreSQL schema 进行比较。更新示例,使文档中记录的约束与生成的列名一致,然后验证 Todo 示例能够针对 PostgreSQL 成功完成迁移。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs, postgresql
- 领域
- databases, documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100