You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Liquibase设置布尔类型默认值遇到问题

Fixing "Invalid default value for 'obsolete'" in Liquibase for MySQL

Got it, let's figure out why you're hitting this error and fix it quickly. The problem here is that MySQL maps Liquibase's type="boolean" to BIT(1), and this type doesn't accept string values like 'false' as a default. Even though you set defaultValueBoolean="0", Liquibase translates that to the string literal which MySQL rejects for BIT columns. Here are a few solid fixes:

Option 1: Use defaultValueNumeric for BIT(1) columns

Since MySQL expects numeric values (0 or 1) for BIT(1) defaults, replace defaultValueBoolean with defaultValueNumeric:

<addColumn tableName="contact_client">
    <column defaultValueNumeric="0" name="obsolete" type="boolean"/>
</addColumn>

This will generate valid SQL: ALTER TABLE myApp.contact_client ADD obsolete BIT(1) DEFAULT 0 NULL which MySQL accepts without issues.

Option 2: Use BOOLEAN type instead (MySQL-friendly)

If you don't strictly need BIT(1), use type="BOOLEAN" (MySQL maps this to TINYINT(1) under the hood, which supports boolean literals). Then your original defaultValueBoolean will work:

<addColumn tableName="contact_client">
    <column defaultValueBoolean="false" name="obsolete" type="BOOLEAN"/>
</addColumn>

The generated SQL will be ALTER TABLE myApp.contact_client ADD obsolete TINYINT(1) DEFAULT false NULL, which is fully compatible with MySQL.

Option 3: Simplify with just defaultValue for BIT(1)

If you want to stick with BIT(1), you can drop the defaultValueBoolean attribute and just use defaultValue="0"—Liquibase will generate the correct numeric default:

<addColumn tableName="contact_client">
    <column defaultValue="0" name="obsolete" type="boolean"/>
</addColumn>

This avoids any conflict between the two default value attributes and produces valid SQL for the BIT type.

Why your original code failed

You had both defaultValue="0" and defaultValueBoolean="0" set. Liquibase prioritized the boolean attribute, translating it to the string 'false'—but MySQL's BIT(1) type doesn't recognize string literals as valid defaults, hence the error.

内容的提问来源于stack exchange,提问作者thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:59:18