loopbackio / loopbackio/loopback-connector-postgresql
Error in your foreign key creations instructions page.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 118
- Forks
- 184
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the foreign-key section linked in the LoopBack Todo list SQL database tutorial and compare its foreignKey value with the PostgreSQL schema produced by migration. Update the example so the documented constraint matches the generated column name, then verify that the Todo example migrates successfully against PostgreSQL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- databases, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100