使用Liquibase删除H2数据库布尔列失败的排查求助
Based on the error you’re encountering and the steps you’ve already tested, let’s break down the likely root causes and actionable fixes tailored to your scenario:
Key Context from Your Situation
- You can successfully drop columns of other data types, so this issue is isolated specifically to boolean columns.
- All attempted methods (direct drop, rename-then-drop, raw SQL) fail, even though the column clearly exists in
information_schema. - You modified a view referencing the boolean column in the same change chain—this is a critical detail that’s almost certainly tied to the problem.
Likely Causes & Corresponding Fixes
1. Stale Metadata Cache from View Dependencies
H2’s metadata cache may not refresh properly after you modify the view, especially when operations run in the same transaction/change set. Even if you updated the view to remove the column reference, H2 might still treat the column as tied to the old view definition.
Fixes:
- Reorder your change sequence: Ensure you fully update the view to remove all references to the boolean column before attempting to drop the column. This eliminates active dependencies that H2 might be checking for.
- Force a metadata refresh: Add this H2-specific SQL step right before your drop column operation in Liquibase to refresh schema metadata:
CALL REBUILD(); -- For H2 1.4.x (your version is 1.4.190) -- For H2 2.x, use: ALTER SCHEMA PUBLIC REFRESH;
2. Missing CASCADE for Dependent Objects
By default, H2 blocks dropping columns that are referenced by views or constraints. Even if you updated the view, residual dependencies (or delayed metadata updates) might still be blocking the drop. The CASCADE keyword tells H2 to automatically remove any dependent objects tied to the column.
Fix:
Replace your drop command with this raw SQL in Liquibase:
ALTER TABLE ce_some_table DROP COLUMN some_column CASCADE;
⚠️ Note: This will delete any remaining views/constraints referencing the column, so confirm your view updates are fully applied first to avoid unintended deletions.
3. Liquibase SQL Generation Quirks
Sometimes Liquibase generates slightly modified SQL that conflicts with H2’s handling of boolean columns. To verify this:
- Enable Liquibase’s debug logging by adding
--log-level=DEBUGto your command, or settinglogLevel=DEBUGin your configuration. - Check the logs for the exact SQL Liquibase sends to H2. Your error message shows a strange space in
SOME_TABLE .SOME_COLUMN—this could indicate formatting issues in the generated SQL that’s causing the "column not found" error.
4. Outdated H2 Version Bug
You’re using H2 version 1.4.190, which is several years old. This version has known bugs related to metadata handling and column operations, especially when views are involved.
Fix:
Try upgrading to a newer stable H2 version:
- For minimal compatibility risk, upgrade to 1.4.200 (the latest in the 1.4.x branch).
- If you can tolerate minor breaking changes, consider moving to H2 2.x (note that this branch has stricter SQL compliance and some syntax adjustments).
Final Testing Steps
- Create a minimal test change set that only updates the view, refreshes metadata, then drops the boolean column—run this in isolation to rule out conflicts with other changes.
- If upgrading H2, test your full migration chain in a staging environment first to catch any compatibility issues.
内容的提问来源于stack exchange,提问作者Bronius Janonis

