简体   繁体   中英

Unrecognized Data Type Sequelize Postgres

Working on a small project where I need to populate a postgres database based on some log data. I've decided to use Sequelize to create my model and db connection.

When trying to call SignalDegs.create() to insert a record I receive the below error message. I've tried to reference DataTypes and import it instead of Sequalize directly resulting in the same error. Any help would be greatly appreciated!.

Error:

throw new Error(`Unrecognized datatype for attribute "${this.name}.${name}"`);
        ^
Error: Unrecognized datatype for attribute 

Model File:

const Sequelize = require('sequelize');
const db = require('../database/index.js');

const SignalDefs = db.define(
  'signaldefs',
  {
    signalType: { primaryKey: true, type: Sequelize.STRING },
    messageSource: { primaryKey: true, type: Sequelize.STRING },
    messageName: { primaryKey: true, type: Sequelize.STRING },
    signalName: { primaryKey: true, type: Sequelize.STRING },
    unit: { primaryKey: true, type: Sequelize.STRING },
    signalID: { autoIncrement: true }
  },
  { freezeTableName: true }
);

const FloatSignals = db.define(
  'floatsignals',
  {
    floatValue: { type: Sequelize.FLOAT },
    time: { primaryKey: true, type: Sequelize.DATE },
    vehicleID: { primaryKey: true, type: Sequelize.INTEGER },
    signal: { primaryKey: true, type: Sequelize.INTEGER }
  },
  { freezeTableName: true }
);

module.exports = { SignalDefs, FloatSignals };

  1. You don't set a type for the signalID field
  2. Are you sure you want almost all fields of the signaldefs model to participate in primary key?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM