здесь мой код (узел: 10188) UnhandledPromiseRejectionWarning: Отказ от необработанного обещания (идентификатор отказа: 1): Ошибка: вставить в значения user
(email
, name
, password
, role
, username
) ('[email protected]', 'chack', 'password', 'user', 'kkkp') - ER_BAD_FIELD_ERROR: Неизвестная колонка 'role' в 'field list' (node: 10188) [DEP0018] DeprecationWarning: Отклонения от необработанных обещаний устарели. В будущем обещание отклонения, которое не обрабатывается, приведет к завершению процесса Node.js с ненулевым кодом выхода.
'use strict';
const Model = require('objection').Model;
const AppConstants = require('./../constants');
class user extends Model {
static get tableName() {
return 'user';
}
static get jsonSchema() {
return {
type: 'object',
required: ['username', 'password', 'email', 'name'],
properties: {
id: { type: 'integer' },
username: {type: 'string',
unique: true ,
minlength: AppConstants.USERNAME_MIN_LENGTH,
maxlength: AppConstants.USERNAME_MAX_LENGTH
},
password: {
type: 'string',
minlength: AppConstants.PASSWORD_MIN_LENGTH,
maxlength: AppConstants.PASSWORD_MAX_LENGTH
},
email: { type: 'string',
index: { unique: true },
},
name: { type: 'string'
},
role: { enum: ['admin', 'user'], ///////////// here is
default: 'user'
}
}
};
}
}
Вы забыли назначить тип в поле role
. Попробуйте это, пожалуйста:
'use strict';
const Model = require('objection').Model;
const AppConstants = require('./../constants');
class user extends Model {
static get tableName() {
return 'user';
}
static get jsonSchema() {
return {
type: 'object',
required: ['username', 'password', 'email', 'name'],
properties: {
id: {type: 'integer'},
username: {
type: 'string',
unique: true,
minlength: AppConstants.USERNAME_MIN_LENGTH,
maxlength: AppConstants.USERNAME_MAX_LENGTH
},
password: {
type: 'string',
minlength: AppConstants.PASSWORD_MIN_LENGTH,
maxlength: AppConstants.PASSWORD_MAX_LENGTH
},
email: {
type: 'string',
index: {unique: true},
},
name: {
type: 'string'
},
role: {
type: 'string',
enum: ['admin', 'user'], ///////////// here is
default: 'user'
}
}
};
}
}