Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize migration fails (postgres)

I am trying to use postgresql with my node application using sequelize. But I can't make it work. When I run sequelize -m I get this output:

Loaded configuration file "config/config.json".
Using environment "development".
Running migrations...
20130916100313-create-table-usuarios.js
Completed in 21ms

events.js:74
        throw TypeError('Uncaught, unspecified "error" event.');
              ^
TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at EventEmitter.emit (events.js:74:15)
    at null.<anonymous> (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/migrator.js:95:44)
    at EventEmitter.emit (events.js:98:17)
    at module.exports.finish (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:138:30)
    at exec (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:92:16)
    at onError (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/query-chainer.js:72:11)
    at EventEmitter.emit (events.js:95:17)
    at /home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/migration.js:65:19
    at null.<anonymous> (/home/alejo/workspace/cloudlogger/api/node_modules/sequelize/lib/emitters/custom-event-emitter.js:52:38)

This is my config.json:

{
  "development": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_dev",
    "dialect":"postgres",
    "protocol":"postgres",
    "host": "127.0.0.1"
  },
  "test": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_test",
    "dialect":"postgres",
    "protocol":"postgres",    
    "host": "127.0.0.1"
  },
  "production": {
    "username": "cloudlogger",
    "password": "foobar",
    "database": "cloudlogger_pro",
    "dialect":"postgres",
    "protocol":"postgres",
    "host": "127.0.0.1"
  }
}

And this is 20130916100313-create-table-usuarios.js

module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable('Usuario',{
      nombre: {
        type: DataTypes.STRING,
        allowBlank: false,
      },
      username: {
        type: DataTypes.STRING,
        unique: true,
      },
      genero: {
        type:   DataTypes.ENUM,
        values: ['Hombre', 'Mujer']
      },
      email: {
        type: DataTypes.STRING,
        unique: true,
        allowBlank: false,
      },
      password_digest: {
        type: DataTypes.STRING,
        allowBlank: false,
      },
      remember_token: DataTypes.STRING,
      superadministrador: {
        type: DataTypes.BOOLEAN,
        defaultValue: false
      },
      token: DataTypes.STRING,
      fecha_token: {
        type: DataTypes.DATE,
        defaultValue: new Date(0)
      },
      lastLogin: DataTypes.DATE
    }).complete(done);
  },
  down: function(migration, DataTypes, done) {
    migration.dropAllTables().complete(done);
  }
}

EDIT

I isolated the error, if I comment or change this lines:

      genero: {
        type:   DataTypes.ENUM,
        values: ['Hombre', 'Mujer']
      },

it works good. It seems to be a problem with ENUM type

like image 990
Alejo Dev Avatar asked Sep 16 '13 16:09

Alejo Dev


1 Answers

Your syntax for ENUMs is just incorrect. Here's what it should be:

type: DataTypes.ENUM('Hombre', 'Mujer')

Check out the sequelize documentation on data types if you have more questions

like image 93
agchou Avatar answered Oct 02 '22 14:10

agchou