简体   繁体   English

回送4-ER_BAD_FIELD_ERROR

[英]Loopback 4 - ER_BAD_FIELD_ERROR

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. 我添加了一个字段role_id,它具有表角色的外键。

I have tried: 我努力了:

  1. Dropping all tables and recreating them again (I am using Liquibase) 删除所有表并再次创建它们(我正在使用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'; 从'@ loopback / repository'导入{实体,模型,属性,belongsTo}; import {Role} from './role.model'; 从'./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);
  }
}

The problem was .... 问题是....

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

name of the model should be 'manager'not 'role' 模型名称应为“经理”而非“角色”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM