gpt4 book ai didi

java - Liquibase:将列更改为 DB2 中的自动增量列(标识)

转载 作者:行者123 更新时间:2023-11-30 01:50:08 30 4
gpt4 key购买 nike

我正在尝试将 BIGINT 列更改为 DB2 中的自动增量列,但我似乎找不到如何操作。我尝试这样做:

    <changeSet id="08.01" author="...">
<addColumn tableName="table_name">
<column name="id" type="bigint">
<constraints nullable="true"/>
</column>

<column name="member_type" type="varchar(100)">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>

<changeSet id="08.02" author="...">
<addAutoIncrement tableName="table_name"
columnDataType="bigint"
columnName="id"/>
</changeSet>

当它运行时,我收到此错误:

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 classpath:db/changelog/08-separation.xml::08.01::author:
Reason: liquibase.exception.DatabaseException: DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=72, DRIVER=4.13.127 [Failed SQL: ALTER TABLE SCHEMATEST.table_name ALTER COLUMN id SET GENERATED BY DEFAULT AS IDENTITY]
at org.springframework.bean
...
...
...
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set classpath:db/changelog/08separation.xml::08.01::author:
Reason: liquibase.exception.DatabaseException: DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=72, DRIVER=4.13.127 [Failed SQL: ALTER TABLE SCHEMATEST.table_name ALTER COLUMN id SET GENERATED BY DEFAULT AS IDENTITY]
...
...
...
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=72, DRIVER=4.13.127

最佳答案

标识列不能为空,这就是error message tells you :

A nullable column cannot be changed to become an identity column.

将列约束更改为 nullable="false" 我猜。

关于java - Liquibase:将列更改为 DB2 中的自动增量列(标识),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56358331/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com