我有一个奇怪的错误:
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)
我添加了一个role_id字段,该字段具有表角色的外键。
我尝试过:
我不确定还能做什么。
我的数据源是:
{
"name": "db",
"connector": "mysql",
"url": "",
"host": "localhost",
"port": 3306,
"user": "root",
"password": "xxx",
"database": "xxx.dev"
}
我的模特:
从'@ loopback / repository'导入{实体,模型,属性,belongsTo}; 从'./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);
}
}
答案 0 :(得分:0)
问题是....
@model({
name: 'role',
settings: {strict: false},
})
模型名称应为'manager'而非'role'