gpt4 book ai didi

liquibase - 如何为loadData文件中的每一行生成主键值

转载 作者:行者123 更新时间:2023-12-04 00:33:43 27 4
gpt4 key购买 nike

使用 Liquibase 填充表时,如何为主键自动增量列生成 id?使用我当前的配置 Liquibase 正在放置 NULL进入 ID 列。

我的变更日志文件:

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd">

<property name="now" value="now()" dbms="mysql,h2"/>
<property name="now" value="current_timestamp" dbms="postgresql"/>

<!--
Added the entity Skill.
-->
<changeSet id="20141029084149" author="jhipster">
<createTable tableName="T_SKILL">
<column name="id" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="value" type="varchar(255)"/>
<column name="description" type="varchar(255)"/>
</createTable>

<loadData encoding="UTF-8"
file="config/liquibase/skills.csv"
separator="|"
tableName="T_SKILL"/>
</changeSet>
</databaseChangeLog>

skills.csv文件:
value|description
java|Java
java-ee|Java Enterprise Edition
junit|JUnit

最佳答案

您需要在 createTable 列标记中包含 autoIncrement="true"

<changeSet id="20141029084149" author="jhipster">
<createTable tableName="T_SKILL">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="value" type="varchar(255)"/>
<column name="description" type="varchar(255)"/>
</createTable>
</changeSet>

关于liquibase - 如何为loadData文件中的每一行生成主键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26629154/

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