Create liquibase diff :
mysql> create database test1 default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use test1
Database changed
mysql> create table a(id int(10), archive bit not null default 0);
Query OK, 0 rows affected (0.04 sec)
mysql> create database test2 default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use test2;
Database changed
mysql> create table a(id int(10));
Query OK, 0 rows affected (0.05 sec)
root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' diffChangeLog --referenceUrl="jdbc:mysql://localhost/test1" --referenceUsername=root --referencePassword='' > diff.xml
Liquibase 'diffChangeLog' Successful
root@82a05bda089b:/opt# cat diff.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" 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 http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="root (generated)" id="1414169048190-1">
<addColumn tableName="a">
<column defaultValue="0" name="archive" type="BIT(1)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
Liquibase update database test2 :
root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' --changeLogFile=diff.xml updateUnexpected error running Liquibase: Error executing SQL ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0': Invalid default value for 'archive'
in mysql-server general_log:
122 Query ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0'
122 Query rollback
mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0';
ERROR 1067 (42000): Invalid default value for 'archive'
mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT 0;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
How to fix?
mysql> create database test1 default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use test1
Database changed
mysql> create table a(id int(10), archive bit not null default 0);
Query OK, 0 rows affected (0.04 sec)
mysql> create database test2 default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use test2;
Database changed
mysql> create table a(id int(10));
Query OK, 0 rows affected (0.05 sec)
root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' diffChangeLog --referenceUrl="jdbc:mysql://localhost/test1" --referenceUsername=root --referencePassword='' > diff.xml
Liquibase 'diffChangeLog' Successful
root@82a05bda089b:/opt# cat diff.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" 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 http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="root (generated)" id="1414169048190-1">
<addColumn tableName="a">
<column defaultValue="0" name="archive" type="BIT(1)">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>
Liquibase update database test2 :
root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' --changeLogFile=diff.xml updateUnexpected error running Liquibase: Error executing SQL ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0': Invalid default value for 'archive'
in mysql-server general_log:
122 Query ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0'
122 Query rollback
mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0';
ERROR 1067 (42000): Invalid default value for 'archive'
mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT 0;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
How to fix?