Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在Objective js中,我试图设置角色并接收错误_Mysql_Node.js_Objection.js - Fatal编程技术网

Mysql 在Objective js中,我试图设置角色并接收错误

Mysql 在Objective js中,我试图设置角色并接收错误,mysql,node.js,objection.js,Mysql,Node.js,Objection.js,这是我的密码 (节点:10188)未处理的Promisejection警告:未处理的承诺拒绝(拒绝id:1):错误:插入到用户(电子邮件,名称,密码,角色,用户名)值('exam@mail.ru“,”查克“,”密码“,”用户“,”kkkp“)-ER\u错误\u字段\u错误:“字段列表”中的未知列“角色” (节点:10188)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程 'use strict'; const Model = r

这是我的密码 (节点:10188)未处理的Promisejection警告:未处理的承诺拒绝(拒绝id:1):错误:插入到
用户
电子邮件
名称
密码
角色
用户名
)值('exam@mail.ru“,”查克“,”密码“,”用户“,”kkkp“)-ER\u错误\u字段\u错误:“字段列表”中的未知列“角色”
(节点:10188)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止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'
                }   
                }
        };
    }
}

您忘记将类型分配给
角色
字段。请试试这个:

'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'
        }
      }
    };
  }
}

非常感谢,我刚刚解决了这个问题,问题在表格方案中