无法向现有模型添加新属性 sails.js
Can't add new attributes to existing model sails.js
我是 sails.js 的新手。我需要在 sails js 中向现有模型添加字段。
这是
module.exports = {
attributes: {
id: {
columnName: 'id',
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
username: {
columnName: 'username',
type: 'STRING',
required: true,
},
userLevel: {
columnName: 'user_level',
type: 'integer',
required: true,
defaultsTo: 1
},
...
但是只要我在我的模型 js 中添加字段,就像
newAttribute: {
columnName: 'new_attribute',
type: 'integer',
required: true
}
我收到一个错误 "E_UKNOWN"。
更准确地说,当我尝试使用更新的模型登录时,我收到此消息:
rr {"data":{"err":{"error":"E_UNKNOWN","status":500,"summary":"Encountered an unexpected error","raw":{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlState":"42S22","index":0}}},"status":401,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"data":{*email and password here*},"url":"auth/login","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"Unauthorized"}
感谢您的帮助。
UPD 如果我将 NODE_ENV 设置为开发,它就会工作。可能是 connection.js 文件的问题?
看来我找到了解决问题的方法。起初我将 NODE_ENV 设置为 development,我想这些表已经创建好了。然后我将 NODE_ENV 更改为生产。现在它可以正常工作,没有奇怪的错误。
我是 sails.js 的新手。我需要在 sails js 中向现有模型添加字段。 这是
module.exports = {
attributes: {
id: {
columnName: 'id',
type: 'integer',
autoIncrement: true,
primaryKey: true,
unique: true
},
username: {
columnName: 'username',
type: 'STRING',
required: true,
},
userLevel: {
columnName: 'user_level',
type: 'integer',
required: true,
defaultsTo: 1
},
...
但是只要我在我的模型 js 中添加字段,就像
newAttribute: {
columnName: 'new_attribute',
type: 'integer',
required: true
}
我收到一个错误 "E_UKNOWN"。 更准确地说,当我尝试使用更新的模型登录时,我收到此消息:
rr {"data":{"err":{"error":"E_UNKNOWN","status":500,"summary":"Encountered an unexpected error","raw":{"code":"ER_BAD_FIELD_ERROR","errno":1054,"sqlState":"42S22","index":0}}},"status":401,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"data":{*email and password here*},"url":"auth/login","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"Unauthorized"}
感谢您的帮助。
UPD 如果我将 NODE_ENV 设置为开发,它就会工作。可能是 connection.js 文件的问题?
看来我找到了解决问题的方法。起初我将 NODE_ENV 设置为 development,我想这些表已经创建好了。然后我将 NODE_ENV 更改为生产。现在它可以正常工作,没有奇怪的错误。