loopbackio / loopbackio/loopback-connector-postgresql

Error in your foreign key creations instructions page.

Abierto
#732 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug
Lenguaje dominante
JavaScript
Estrellas
118
Forks
184
Merge medio
1 d 22 h
PR fusionados (30 d)
5

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza por la sección sobre claves foráneas enlazada en el tutorial de base de datos SQL de la lista Todo de LoopBack y compara su valor foreignKey con el esquema de PostgreSQL producido por la migración. Actualiza el ejemplo para que la restricción documentada coincida con el nombre de columna generado y, después, verifica que el ejemplo Todo se migre correctamente contra PostgreSQL.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, nodejs, postgresql
Área
databases, documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.