Liquibase插入BIT列,MySQL,数据太长而无法进入列

2022-09-01 21:50:58

在 Liquibase 中,我定义了一个表,其列类型为 BIT(1)

<changeSet author="foobar" id="create-configuration-table">
    <createTable tableName="configuration">
        <column autoIncrement="true" name="id" type="BIGINT(19)">
            <constraints primaryKey="true" />
        </column>
        <column name="active" type="BIT(1)" />
        <column name="version" type="INT(10)" />
    </createTable>
</changeSet>

在随后的变更集中,我想将数据插入到此表中,但是,将数据插入BIT(1)类型的“活动”列时,MySQL会抱怨“数据截断:数据对于列来说太长了”

我试过:

<insert>
   <column name="active" value="1" type="BIT(1)" />
</insert>

<insert>
   <column name="active" value="1"/>
</insert>

<insert>
   <column name="active" value="TRUE" type="BOOLEAN"/>
</insert>

插入 BIT(1) 列的正确方法是什么?


答案 1

回答我自己的问题,因为我在发布后立即想到了这一点。要插入到 BIT(1) 列中, 您需要将值定义为valueBoolean

<insert>
   <column name="active" valueBoolean="true"/>
</insert>

答案 2

使用 从 csv 文件加载每个表的记录时,也存在类似的情况。在该元素中,您必须为表中的每个布尔列显式指定类型:<loadData><loadData>

<loadData encoding="UTF-8"
          file="path/to/file.csv"
          separator=","
          tableName="MY_TABLE"
>
    <!-- specify that values in my_boolean_column should be interpreted as Boolean values -->
    <column name="my_boolean_column" type="BOOLEAN" />
</loadData>

希望它能帮助其他来到这里的人。


推荐