0

尝试升级/迁移数据库时,我似乎遇到了异常。我似乎一直在工作,直到它到达某一行,即 48586。我重新测试,好像数据已损坏,但同样的事情再次发生。mysql 试图做的是删除表 Logs 的当前主键,然后添加新的主键IP, logId, logTime

SEVERE 10/15/12 2:27 PM:liquibase: Error executing SQL ALTER TABLE `Logs` ADD PRIMARY KEY (`IP`, `logId`, `logTime`)
java.sql.SQLException: Data truncated for column 'logTime' at row 48586
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569)
        at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:824)
        at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:667)
        at liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:92)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:105)
        at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1014)
        at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:998)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.update(Liquibase.java:113)
        at liquibase.integration.commandline.Main.doMigration(Main.java:684)
        at liquibase.integration.commandline.Main.main(Main.java:116)
4

1 回答 1

2

MySQL 词汇表中所述:

首要的关键

一组列——隐含地,基于这组列的索引——可以唯一地标识表中的每一行。因此,它必须是不包含任何NULL值的唯一索引。

CREATE TABLESyntax下,然后手册解释:

APRIMARY KEY是一个唯一索引,其中所有键列都必须定义为NOT NULL。如果它们没有显式声明为NOT NULL,MySQL 会隐含地(并且默默地)声明它们。

您的列似乎logTime允许(并包含)NULL值;试图PRIMARY KEY在它上面创建一个导致该列被静默声明为NOT NULL,从而将任何值“截断”NULL为该列的默认值:错误类似于ER_WARN_NULL_TO_NOTNULL.

于 2012-10-19T10:38:45.907 回答