loopbackio / loopbackio/loopback-connector-postgresql
Error in your foreign key creations instructions page.
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 118
- フォーク
- 184
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
LoopBack Todo リストの SQL データベースチュートリアルにリンクされている外部キーのセクションから始め、その foreignKey の値を、マイグレーションによって生成された PostgreSQL スキーマと比較します。ドキュメントに記載された制約が生成されたカラム名と一致するように例を更新し、その後、Todo の例が PostgreSQL に対して正常にマイグレーションできることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, nodejs, postgresql
- 領域
- databases, documentation
- issue の種類
- ドキュメント
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100