我想创建 liquibase 的脚本。当我在下一个脚本中执行插入操作时,我想通过 UUID 自动生成 id。 我尝试了在那里找到的东西: 编辑:我使用了一个答案:
<property name="u_id" value="uuid()" dbms="mysql"/>
<changeSet id="1" author="xyz">
<createTable tableName="persons">
<column name="id" type="varchar(36)" defaultValueComputed="${u_id}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="surname" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="email" type="varchar(50)">
<constraints nullable="false" unique="true"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
第一个脚本正常,表已创建,但是当我添加第二个脚本时:
<changeSet id="2" author="xyz">
<insert tableName="persons">
<column name="name" value="name value"/>
<column name="surname" value="surname value"/>
<column name="email" value="email value"/>
</insert>
</changeSet>
现在错误是:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for change set db/version/V1__create_persons_table.xml::1::xyz: Reason: liquibase.exception.DatabaseException: 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 'uuid() NOT NULL, name VARCHAR(50) NOT NULL, surname VARCHAR(50) NOT NULL' at line 1 [Failed SQL: (1064) CREATE TABLE ticketapidatabase.persons (id VARCHAR(36) DEFAULT uuid() NOT NULL, name VARCHAR(50) NOT NULL, surname VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, CONSTRAINT PK_PERSONS PRIMARY KEY (id), UNIQUE (email))]
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您的
id列定义应如下所示: