2013-09-16 110 views
6

我正在嘗試使用postgresql和我的節點應用程序使用sequelize。但我無法讓它工作。當我運行sequelize -m我得到這個輸出:續集遷移失敗(postgres)

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) 

這是我的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" 
    } 
} 

這是20130916100313創建表,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); 
    } 
} 

編輯

我孤立了錯誤,如果我c省略或更改此行:

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

它工作良好。這似乎是一個ENUM類型的問題

回答

2

您的語法ENUMs只是不正確的。下面是它應該是什麼:

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

檢查出data types的sequelize文檔,如果您有更多問題

+0

剛一說明,這似乎在最新的改變http://docs.sequelizejs.com/en/latest/docs /模型定義/ – theptrk