loopbackio / loopbackio/loopback-next

Cannot migrate database schema error: The associated field "todoListId" in the foreign key constraint does not exist"

Open
#8,685 0 comments 0 reactions 1 assignee View on GitHub

@achrinza is already working on this.

Since Jun 26, 2022.

bug Docs
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

### Describe the bug

## What is the problem
When I was doing code practice in the **Running on relational databases** section, running `npm run migrate` reported an error:
`Cannot migrate database schema error: The associated field "todoListId" in the foreign key constraint does not exist`,
## The connected DB
Consistent with tutorial - Postgre DB

## How I handle it
**Change the value of the foreignKey to full lowercase**
todo.model.ts
```
@model({
settings: {
postgresql: {
schema: 'lb4', // schema name
table: 'todo' // table name
},
foreignKeys: {
fk_todo_todoListId: {
name: 'fk_todo_todoListId',
entity: 'TodoList',
entityKey: 'id',
foreignKey: 'todolistid', // The value in the official tutorial is todoListId
},
}
}
})
export class Todo extends Entity {
// etc
}
```

## Suggestion
**Whether the code content should be changed in the tutorial**
**Transform**: foreignKey: 'todoListId' -> foreignKey: 'todolistid'

### Logs

_No response_

### Additional information

_No response_

### Reproduction

https://github.com/RokeyJoe/Loopback4-todo-list.git

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.