【发布时间】:2015-03-07 04:46:35
【问题描述】:
我的环境:
- java: 1.8.0_20, 64 位
- liquibase:3.3.1
- mysql: 5.5.34
- mysql 连接器:mysql-connector-java-5.1.34-bin.jar
- mysql驱动:com.mysql.jdbc.Driver
- mysql连接字符串:jdbc:mysql://localhost/my_db
- mysql用户:root用户
- 操作系统:Windows 7 64
数据库更改日志 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-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">
<changeSet author="jbenton" id="create my_test_tbl table">
<sql> SET storage_engine=MYISAM; </sql>
<createTable tableName="my_test_tbl">
<column autoIncrement="true" name="my_test_tbl_id" type="INT UNSIGNED">
<constraints primaryKey="true"/>
</column>
<column defaultValueNumeric="0" name="col_smallint" type="SMALLINT">
<constraints nullable="false"/>
</column>
<column defaultValueNumeric="0" name="col_smallint_unsigned" type="SMALLINT UNSIGNED"/>
<column defaultValueNumeric="0" name="col_smallint_unsigned_not_null" type="SMALLINT UNSIGNED">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
使用updateSql 命令,我看到正在生成以下sql
CREATE TABLE my_db.my_test_tbl (
my_test_tbl_id INT AUTO_INCREMENT NOT NULL,
col_smallint SMALLINT DEFAULT 0 NOT NULL,
col_smallint_unsigned SMALLINT DEFAULT 0 NULL,
col_smallint_unsigned_not_null SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT PK_MY_TEST_TBL PRIMARY KEY (my_test_tbl_id));
我的目标是列是SMALLINT UNSIGNED。是不是我做错了什么?
【问题讨论】:
-
抱歉,我真的不知道这里有什么问题。查看源代码,我可以在
SmallIntType.java类上看到评论/always smallint regardless of parameters passed。我不监督整个代码,因此不能确定这是否真的表明该类型的其他参数(如“无符号”)被遗漏了。也许您可以为此在 liquibase-github 上提交错误/增强功能? -
我会提交一个错误。我只是想确保我没有遗漏任何明显的东西。我在 stackoverflow 上看到了几个例子,似乎这对其他人有用。请注意,id 是一个 int,我将其定义为“int unsigned”,它最终是一个普通的旧 int。
-
在 3.3.2 版中
type="BIGINT UNSIGNED"即使它也只是创建了BIGINT(20)而不是未签名 -
有些人说 UNSIGNED 不是 SQL 标准。所以可能不支持 liquibase。