3
我在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文件的問題?
我會懷疑,因爲你說你的新字段是必需的,而你現有的數據沒有它,它會拋出一個錯誤。你有沒有嘗試給這個領域一個'defaultsTo'? – Tholle
是的,我試過了。不起作用 – alyona
織補。如果您處於開發環境中,是否嘗試過在'config/models.js'中設置'migrate:'alter''?這種方式帆將嘗試爲您解決它。還是一個實驗性功能。 – Tholle