Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SailsJS/MySQL: Unknown column 'NaN' in 'field list'

I found that I am getting

Error (E_UNKNOWN) :: Encountered an unexpected error : ER_BAD_FIELD_ERROR: Unknown column 'NaN' in 'field list'

I first noticed this on staging (elastic beanstalk). Then noticed this locally when I do a fresh npm install. How can I debug whats wrong? It appears that

Survey.create(params)

is the cause. But I cannot figure out why ... params look like

{
  "name": "ADDSW",
  "description": "rewgre",
  "url": "https://www.surveymonkey.com/r/my-survey-name?uid=[uid_value]&sid=[sid_value]",
  "image": "https://s3-ap-southeast-1.amazonaws.com/meclub/savVD/35/zx.jpg",
  "points": "111",
  "trackingCode": "EN201510EXFABPSSADON",
  "transaction_partner": "EX",
  "transaction_department": "FAB",
  "transaction_campaign": "ADON",
  "win": ""
}

And the survey model:

var shortid = require('shortid');

module.exports = {
    autoPK: false,

    attributes: {
        id: {
            type: 'string',
            unique: true,
            index: true,
            primaryKey: true,
            defaultsTo: function() {
                return shortid.generate();
            }
        },
        name: {
            type: 'string',
            required: true
        },
        description: {
            type: 'string',
            defaultsTo: ''
        },
        url: {
            type: 'string',
            required: true
        },
        image: {
            type: 'string',
            required: true
        },
        points: {
            type: 'integer',
            required: true
        },

        win: {
            model: 'win'
        },

        trackingCode: {
            type: 'string',
            required: true
        },
        transaction_partner: {
            type: 'string'
        },
        transaction_department: {
            type: 'string'
        },
        transaction_campaign: {
            type: 'string'
        },

        toJSON: function() {
            var obj = this.toObject();
            obj = _.omit(obj, ['createdAt', 'updatedAt', 'transaction_partner', 'transaction_department', 'transaction_campaign']);

            return obj;
        }
    }
}

Seems like some package causes the error? But I cannot figure out which ...

UPDATE

Just tried removing all the ^ and ~ in the version numbers in package.json so all dependencies are installed at exact versions, but it still fails ...

like image 401
Jiew Meng Avatar asked Nov 09 '22 04:11

Jiew Meng


1 Answers

I guess the problem is with the win attribute. Instead of sending empty string "win": "", you may have to eliminate it.

like image 58
Bipin Bhandari Avatar answered Nov 15 '22 04:11

Bipin Bhandari