sequelize: Show indexes query on Postgres fails to return functional indexes
Model:
module.exports = function(sequelize, DataTypes) {
var Model = sequelize.define('Company', {
name: {
type: DataTypes.STRING,
unique: true
}
}, {
indexes: [
{ name: 'unique_name', unique: true, fields: [sequelize.fn('lower', sequelize.col('name'))] }
]
});
return Model;
};
It works when the database is empty. But when I stop the server and then run it again. It throws this error:
Possibly unhandled SequelizeDatabaseError: relation "unique_name" already exists
at module.exports.Query.formatError (/Users/johnkevinmbasco/webapps/helpdesk/node_modules/sequelize/lib/dialects/postgres/query.js:415:16)
at null.<anonymous> (/Users/johnkevinmbasco/webapps/helpdesk/node_modules/sequelize/lib/dialects/postgres/query.js:110:21)
at emit (events.js:95:17)
at Query.handleError (/Users/johnkevinmbasco/webapps/helpdesk/node_modules/pg/lib/query.js:99:8)
at null.<anonymous> (/Users/johnkevinmbasco/webapps/helpdesk/node_modules/pg/lib/client.js:166:26)
at emit (events.js:95:17)
at Socket.<anonymous> (/Users/johnkevinmbasco/webapps/helpdesk/node_modules/pg/lib/connection.js:109:12)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:764:14)
at Socket.emit (events.js:92:17)
The contents of my /bin/www file is similar to this - https://github.com/sequelize/express-example/blob/master/bin/www
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (12 by maintainers)
Whats the output of
sequelize.QueryInterface.showIndex(Model.getTableName())
. Seems like it does not find the existing index correctly.Are you using schemas?