2013-09-16 33 views
6

Tôi đang cố gắng sử dụng postgresql với ứng dụng nút của tôi bằng cách sử dụng phần tiếp theo. Nhưng tôi không thể làm cho nó hoạt động được. Khi tôi chạy sequelize -m tôi nhận được kết quả này:Di chuyển phần tiếp theo không thành công (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) 

Đây là config.json tôi:

{ 
    "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" 
    } 
} 

Và đây là 20130916100313-tạo-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

Tôi đã tách lỗi, nếu tôi c bỏ qua hoặc thay đổi dòng này:

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

hoạt động tốt. Dường như có vấn đề với ENUM loại

Trả lời

2

Cú pháp của bạn cho ENUM chỉ là không chính xác. Dưới đây là những gì nó nên là:

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

Kiểm tra các tài liệu hướng dẫn sequelize trên data types nếu bạn có thắc mắc

+0

Chỉ cần một lưu ý, điều này dường như được thay đổi trong mới nhất http://docs.sequelizejs.com/en/latest/docs/models-definition / – theptrk

Các vấn đề liên quan