gpt4 book ai didi

mysql - 在反对 js 中,我试图设置一个角色并收到错误

转载 作者:行者123 更新时间:2023-11-29 10:22:18 27 4
gpt4 key购买 nike

这是我的代码( Node :10188)UnhandledPromiseRejectionWarning:未处理的 promise 拒绝(拒绝ID:1):错误:插入用户(电子邮件名称密码角色用户名)值('exam@mail.ru'、'chack'、'密码'、'用户'、'kkkp' ) - ER_BAD_FIELD_ERROR:“字段列表”中的未知列“角色”( Node :10188)[DEP0018] DeprecationWarning:未处理的 promise 拒绝已被弃用。将来,未处理的 Promise 拒绝将会以非零退出代码终止 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'
}
}
};
}
}

关于mysql - 在反对 js 中,我试图设置一个角色并收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49024633/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com