loopbackio / loopbackio/loopback-connector-postgresql

Error in your foreign key creations instructions page.

Offen
#732 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
JavaScript
Sterne
118
Forks
184
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
5

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem im SQL-Datenbanktutorial für die LoopBack-Todo-Liste verlinkten Abschnitt zu Fremdschlüsseln und vergleiche dessen Wert foreignKey mit dem durch die Migration erzeugten PostgreSQL-Schema. Aktualisiere das Beispiel so, dass die dokumentierte Einschränkung mit dem generierten Spaltennamen übereinstimmt, und überprüfe anschließend, dass das Todo-Beispiel erfolgreich gegen PostgreSQL migriert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, nodejs, postgresql
Bereich
databases, documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.