我目前在我的数据库中有一个枚举类型,是通过Liquibase创建的,并使用以下脚本:
- changeSet:
id: id_1
author: my_team
changes:
- sql: CREATE TYPE my_team.letters AS ENUM ('A', 'B', 'C')
因为我需要向枚举中添加字母D,所以我创建了一个新的枚举
- changeSet:
id: id_2
author: my_team
changes:
- sql: CREATE TYPE my_team.letters_2 AS ENUM ('A', 'B', 'C', 'D')
我更新了类型
- changeSet:
id: id_3
author: my_team
changes:
- modifyDataType:
columnName: letter
newDataType: my_team.letters_2
schemaName: my_team
tableName: table_name
执行 Liquibase 脚本时,我遇到了以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set db/changelog/ddl-my_team-v.0.0.15.my_team::id_3::my_team team:
Reason: liquibase.exception.DatabaseException: ERROR: cannot cast type my_team.letters to my_team.letters_2
Position: 89 [Failed SQL: (0) ALTER TABLE my_team.table_name ALTER COLUMN case_status TYPE my_team.letters_2 USING (letter::my_team.letters_2)]
我无法理解为什么这样做,因为目标类型包含了原始类型的所有值。
是否有其他方法可以实现此功能?
谢谢提前!
runInTransaction="false"
即可! - Blockost