2
votes

I am facing the following error in Sails when I run sails lift which is as follows

usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/util /schema.js:59
attributes[key].type = attributes[key].type.toLowerCase();                                                  
TypeError: undefined is not a function
at        /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/util s/schema.js:59:51
at Array.forEach (native)
at Object.schema.normalizeAttributes  (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/uti ls/schema.js:45:22)
at module.exports (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/core/index.js:42:34)
at module.exports (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/collection/index.js:44:8)
at new child (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/utils/extend.js:17:39)
at initialize (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/collection/loader.js:37:10)
at loadCollection (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline.js:112:29)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:162:20
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:230:13
at _arrayEach (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:81:9)
at _each (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:72:13)
at Object.async.forEachOf.async.eachOf (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:229:9)
at Object.async.forEach.async.each (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:206:22)
at Array.async.auto.loadCollections (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline.js:125:13)
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:590:38

My model has the following attributes

SerialNo: {
  type: 'integer',
  unique: true,
  required: true,
  index: true
},

CreatedAt: {
  type: Date,
  default: Date.now
}

I don't understand the error. I have no functions in the corresponding controller. I also have not defined any routes as of now.

Can somebody help me with this error?

1
You don't have to use a createdAt attribute which exists implicitly - Yann Bertrand
The Date type doesn't exist in Waterline, you'll have to use type: 'datetime' - Yann Bertrand
The default attribute option doesn't exist. You can use defaultsTo - Yann Bertrand
@YannBertrand. I did Type 'datetime ' and it worked for for me. Also when I did type='date', I still got output. Can you tell is there an difference between the two. - shubhamagiwal92

1 Answers

0
votes

in Your Model you have to change your model like this :

SerialNo: {
  type: 'integer',
  unique: true,
  required: true,
  index: true
},

CreatedAt: {
  type: 'Date',
  default: Date.now
}

note : in sails type must have this ' '