-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Closed
Copy link
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).For issues and PRs. Things that involve MySQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
What you are doing?
Here's my migration:
'use strict';
module.exports = {
up: function (queryInterface, Sequelize) {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
return queryInterface.createTable(
'notifications_subscriptions',
{
id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
userId: {
type: Sequelize.STRING(20),
allowNull: false
}
}
).then(function () {
return [
// Add indexes
queryInterface.addIndex(
'notifications_subscriptions',
['id', 'userId'],
{
indexName: 'notifications_subscriptions-id-userId'
}
)
];
});
},
down: function (queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.dropTable('users');
*/
return queryInterface.removeIndex('notifications_subscriptions', '`notifications_subscriptions-id-userId`')
.then(function(){
queryInterface.dropTable('notifications_subscriptions');
});
}
};What do you expect to happen?
The migration to go up and down successfully
What is actually happening?
The migration goes up, but when going down there's this error:
Unhandled rejection SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-id-userId ON `notification_subscription`' at line 1
at Query.formatError (/src/database/node_modules/sequelize/lib/dialects/mysql/query.js:175:14)
at Query._callback (/src/database/node_modules/sequelize/lib/dialects/mysql/query.js:49:21)
at Query.Sequence.end (/src/database/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Query.ErrorPacket (/src/database/node_modules/mysql/lib/protocol/sequences/Query.js:94:8)
at Protocol._parsePacket (/src/database/node_modules/mysql/lib/protocol/Protocol.js:280:23)
at Parser.write (/src/database/node_modules/mysql/lib/protocol/Parser.js:73:12)
at Protocol.write (/src/database/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/src/database/node_modules/mysql/lib/Connection.js:96:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:535:20)
I've worked around it by wrapping the index name string with backticks:
return queryInterface.removeIndex('notifications_subscriptions', '`notifications_subscriptions-id-userId`')
Dialect: mysql
Database version: 5.7.12
Sequelize version: Node: 6.0.0, CLI: 2.4.0, ORM: 3.22.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dialect: mysqlFor issues and PRs. Things that involve MySQL (and do not involve all dialects).For issues and PRs. Things that involve MySQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type