2014-10-29 22 views
1

如何在使用Liquibase填充表時爲主鍵自動增量列生成id?用我目前的配置,Liquibase將NULL放入ID列。如何爲loadData文件中的每一行生成主鍵值

我的changelog文件:

<?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 

回答

3

您需要包括自動增量在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> 
相關問題