Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpressJS - Sequelize - Unrecognized Data Type

I manually created a sql database and am now trying to set up my sequelize models to match the columns in my sql tables, but I've run into an issue with my model related to an unrecognized field type. I can't seem to pinpoint the error and if it is related to not matching the data type for a field in my database or that the sequelize does not recognize some of my code.

Here is my error:

/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/lib/model.js:90
      throw new Error('Unrecognized data type for field ' + name);
            ^
Error: Unrecognized data type for field pattern
    at null.<anonymous> (/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/lib/model.js:90:13)
    at /Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/node_modules/lodash/index.js:2874:23
    at /Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/node_modules/lodash/index.js:3395:24
    at /Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/node_modules/lodash/index.js:3073:15
    at baseForOwn (/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/node_modules/lodash/index.js:2046:14)
    at Function.mapValues (/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/node_modules/lodash/index.js:3394:9)
    at new Model (/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/lib/model.js:74:50)
    at Sequelize.define (/Users/user/Desktop/Projects/node/assistant/node_modules/sequelize/lib/sequelize.js:577:15)
    at Object.<anonymous> (/Users/user/Desktop/Projects/node/assistant/app/models/imagesModel.js:9:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/user/Desktop/Projects/node/assistant/app/routes.js:4:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

Here is my model:

var Sequelize      = require('sequelize');
var sequelize = new Sequelize('db', 'admin', 'pwd', {
    host: 'database-host',
    port: 3306,
    dialect: 'mysql'
});


var Images = sequelize.define('images', {
    pattern: {
        type: sequelize.STRING,
        field: 'pattern'
    },
    color: {
        type: sequelize.STRING,
        field: 'color'
    },
    imageUrl: {
        type: sequelize.STRING,
        field: 'imageUrl'
    },
    imageSource: {
        type: sequelize.STRING,
        field: 'imageSource'
    },
    description_id: {
        type: sequelize.INTEGER,
        field: 'description_id'
    }
});

module.exports = Images;
like image 531
cphill Avatar asked Oct 15 '15 02:10

cphill


1 Answers

I think that your code should be:

var Sequelize      = require('sequelize');
var sequelize = new Sequelize('db', 'admin', 'pwd', {
    host: 'database-host',
    port: 3306,
    dialect: 'mysql'
});


var Images = sequelize.define('images', {
    pattern: {
        type: Sequelize.STRING,
        field: 'pattern'
    },
    color: {
        type: Sequelize.STRING,
        field: 'color'
    },
    imageUrl: {
        type: Sequelize.STRING,
        field: 'imageUrl'
    },
    imageSource: {
        type: Sequelize.STRING,
        field: 'imageSource'
    },
    description_id: {
        type: Sequelize.INTEGER,
        field: 'description_id'
    }
});

module.exports = Images;

You can refer to http://docs.sequelizejs.com/en/latest/api/datatypes/, http://docs.sequelizejs.com/en/latest/docs/models-definition/ or an example here: https://github.com/thanhson1085/angular-admin-seed/blob/master/server/models/user.js

like image 132
Nguyen Sy Thanh Son Avatar answered Nov 19 '22 17:11

Nguyen Sy Thanh Son