0

I am having a weird error:

    Unhandled error in GET /managers: 
    500 Error: ER_BAD_FIELD_ERROR: Unknown column 'role_id' in 'field list'
    at Query.Sequence._packetToError
    (/Users/xxxx/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)

I have added a field role_id which has a foreign key to a table role.

I have tried:

  1. Dropping all tables and recreating them again (I am using Liquibase)
  2. Droping database
  3. Creating a database with different name

I am not sure what else to do.

My Datasource is:

{
  "name": "db",
  "connector": "mysql",
  "url": "",
  "host": "localhost",
  "port": 3306,
  "user": "root",
  "password": "xxx",
  "database": "xxx.dev"
}

My model:

import {Entity, model, property, belongsTo} from '@loopback/repository'; import {Role} from './role.model';

@model({
  name: 'role',
  settings: {strict: false},
})
export class Manager extends Entity {
  @property({
    type: 'number',
    id: true,
    required: true,
  })
  id: number;

  @belongsTo(() => Role, {
    name: 'role',
  })
  role_id: number;

  @property({
    type: 'string',
    required: true,
  })
  first_name: string;

  @property({
    type: 'string',
    required: true,
  })
  last_name: string;

  [props: string]: any;

  constructor(data?: Partial<Manager>) {
    super(data);
  }
}
Eduardo
  • 1,781
  • 3
  • 26
  • 61

1 Answers1

0

The problem was ....

@model({
  name: 'role',
  settings: {strict: false},
})

name of the model should be 'manager'not 'role'

Eduardo
  • 1,781
  • 3
  • 26
  • 61