我创建了一个迁移文件以将列添加为up
,然后在down
.
这是迁移文件代码:
module.exports = {
up: (queryInterface, Sequelize) =>
queryInterface.addColumn('Books', 'Rating', {
allowNull: false,
type: Sequelize.ENUM('like', 'dislike'),
}),
down: (queryInterface, Sequelize) => {
queryInterface.removeColumn('Books', 'Rating');
},
};
当我第一次使用 运行它时db:migrate
,它成功添加了列,但是当我执行 adb:migrate:undo:all
然后再次运行迁移时,它给我一个错误 sqing
======= 20180211100937-AddedRatingIntoBooks: migrating
======= 2018-02-11 15:42:46.076 IST
[64531] ERROR: type "enum_Books_Rating" already exists 2018-02-11 15:42:46.076 IST
[64531] STATEMENT: CREATE TYPE "public"."enum_Books_Rating" AS ENUM('like', 'dislike');
ALTER TABLE "public"."Boo ks" ADD COLUMN "Rating" "public"."enum_Books_Rating";
ERROR: type "enum_Books_Rating" already exists
这里的问题仍然存在。