loopbackio / loopbackio/loopback-connector-postgresql
Error in your foreign key creations instructions page.
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 118
- Forks
- 184
- Merge moyen
- 1 j 22 h
- PR mergées (30 j)
- 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?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la section sur les clés étrangères liée dans le tutoriel de base de données SQL de la liste Todo de LoopBack et comparez sa valeur foreignKey avec le schéma PostgreSQL produit par la migration. Mettez à jour l’exemple afin que la contrainte documentée corresponde au nom de colonne généré, puis vérifiez que l’exemple Todo est correctement migré avec PostgreSQL.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, nodejs, postgresql
- Domaine
- databases, documentation
- Type d'issue
- Documentation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 45/100