在使用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
答案 0 :(得分:3)
你需要包含autoIncrement =&#34; true&#34;在createTable列标记
中<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>