通过liquibase创建表时出现MySQL错误

时间:2011-07-06 14:12:08

标签: mysql grails mysql-error-1064 liquibase

我通过数据库迁移插件0.2.1使用Grails 1.3.7 + MySQL 5.5 + Liquibase。

当我在开发环境中时,我将Hibernate配置为使用“create-drop”,但在我的QA环境中,我想使用liquibase来创建我的表。这是我的环境配置:

environments {
    development {
        dataSource {
            configClass = GrailsAnnotationConfiguration.class
            pooled = false
            driverClassName = "com.mysql.jdbc.Driver"
            username = "root"
            password =  ""
            dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
            dbCreate = "create-drop"
            url = "jdbc:mysql://localhost/dripita_dev"      
        }
    }
    localQa {
        dataSource {
            configClass=GrailsAnnotationConfiguration.class
            pooled=false
            driverClassName="com.mysql.jdbc.Driver"
            username="root"
            password=""
            dialect="org.hibernate.dialect.MySQL5InnoDBDialect"
            url="jdbc:mysql://localhost/dripita_localqa"        
        }
    }
 ...
}

当我以开发模式启动应用程序时,数据库表可以正常创建。我执行以下操作来创建更改日志:

$ grails dbm-generate-gorm-changelog changelog.groovy

看起来像这样:

changeSet(author: "javidjamae (generated)", id: "1309959832163-2") {
    createTable(tableName: "payment") {
        column(autoIncrement: "true", name: "id", type: "bigint") {
            constraints(nullable: "false", primaryKey: "true", primaryKeyName: "paymentPK")
        }

        column(name: "version", type: "bigint") {
            constraints(nullable: "false")
        }

        column(name: "buyer_id", type: "bigint") {
            constraints(nullable: "false")
        }

        column(name: "buyer_information_id", type: "bigint")

        column(name: "currency", type: "varchar(255)") {
            constraints(nullable: "false")
        }

        column(name: "discount_cart_amount", type: "decimal(19,2)") {
            constraints(nullable: "false")
        }

        column(name: "paypal_transaction_id", type: "varchar(255)")

        column(name: "status", type: "varchar(9)") {
            constraints(nullable: "false")
        }

        column(name: "tax", type: "double precision(19)") {
            constraints(nullable: "false")
        }

        column(name: "transaction_id", type: "varchar(255)")
    }
}

然后我尝试从更改日志中创建表:

$ grails -Dgrails.env=localQa dbm-update

但是,当我运行dbm-update时,我收到以下错误:

07/06 08:52:41 INFO  [main]: liquibase  - Successfully acquired change log lock
07/06 08:52:42 INFO  [main]: liquibase  - Reading from `DATABASECHANGELOG`
07/06 08:52:42 INFO  [main]: liquibase  - Reading from `DATABASECHANGELOG`
07/06 08:52:42 ERROR [main]: liquibase  - Error executing SQL CREATE TABLE `payment` (`id` BIGINT AUTO_INCREMENT  NOT NULL, `version` BIGINT NOT NULL, `buyer_id` BIGINT NOT NULL, `buyer_information_id` BIGINT, `currency` VARCHAR(255) NOT NULL, `discount_cart_amount` decimal(19,2) NOT NULL, `paypal_transaction_id` VARCHAR(255), `status` VARCHAR(9) NOT NULL, `tax` double precision(19) NOT NULL, `transaction_id` VARCHAR(255), CONSTRAINT `paymentPK` PRIMARY KEY (`id`)) ENGINE=InnoDB
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') NOT NULL, `transaction_id` VARCHAR(255), CONSTRAINT `paymentPK` PRIMARY KEY (`' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)

当我在MySQL中复制/粘贴create语句时,我得到了同样的错误。我甚至关闭了ENGINE = InnoDB,看看是否有所作为,但事实并非如此。有什么想法吗?

仅供参考:我在Mac上使用HomeBrew安装了MySQL。

1 个答案:

答案 0 :(得分:2)

我的猜测是你的QA数据库不知道数据类型double precision(19)是什么 尝试将其更改为double precision

如果失败,请考虑使用其他数据类型:doc表示双精度是“非标准变体”