2

在尝试执行应向表中添加列的变更集时:

<changeSet id="2013.06.25_2" author="ama">  
    <preConditions onFail="MARK_RAN">  
        <not>  
            <columnExists tableName="T_FORCED_DATA" columnName="TRADE_KEY_ID"/>  
        </not>  
</preConditions>  
    <comment>Add column T_FORCED_DATA.TRADE_KEY_ID</comment>  
    <addColumn tableName="T_FORCED_DATA">  
        <column name="TRADE_KEY_ID" type="numeric(10,0)" defaultValue="NULL">  
            <constraints nullable="true" references="T_TRADE_KEY" foreignKeyName="TRADE_KEY_ID" />  
        </column>  
    </addColumn>  
</changeSet>  

我收到以下错误:

SEVERE 6/25/13 5:35 PM:liquibase: Change Set db/changelog/_2013/_06/_05/update_T_FORCED_DATA.xml::2013.06.25_2::ama failed.  Error: Don't know how to find table and column names from T_TRADE_KEY liquibase.exception.UnexpectedLiquibaseException: Don't know how to find table and column names from T_TRADE_KEY  
    at liquibase.sqlgenerator.core.AddColumnGenerator.addForeignKeyStatements(AddColumnGenerator.java:93)  
    at liquibase.sqlgenerator.core.AddColumnGeneratorDefaultClauseBeforeNotNull.generateSql(AddColumnGeneratorDefaultClauseBeforeNotNull.java:91)  
    at liquibase.sqlgenerator.core.AddColumnGeneratorDefaultClauseBeforeNotNull.generateSql(AddColumnGeneratorDefaultClauseBeforeNotNull.java:26)  
    at liquibase.sqlgenerator.SqlGeneratorChain.generateSql(SqlGeneratorChain.java:30)  
    at liquibase.sqlgenerator.SqlGeneratorFactory.generateSql(SqlGeneratorFactory.java:150)  
    at liquibase.executor.AbstractExecutor.applyVisitors(AbstractExecutor.java:22)  
    at liquibase.executor.jvm.JdbcExecutor.access$000(JdbcExecutor.java:36)  
    at liquibase.executor.jvm.JdbcExecutor$1ExecuteStatementCallback.doInStatement(JdbcExecutor.java:82)  
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)  
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104)  
    at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1091)  
    at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1075)  
    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:114)  
    at org.liquibase.maven.plugins.LiquibaseUpdate.doUpdate(LiquibaseUpdate.java:31)  
    at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask(AbstractLiquibaseUpdateMojo.java:24)  
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:305)  
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)  
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)  
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)  
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)  
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)  
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)  
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)  
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)  
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)  
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)  
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)  
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)  
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)  
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
    at java.lang.reflect.Method.invoke(Method.java:601)  
    at   org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)  
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)  
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)  
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)  

有谁知道我为什么会得到这个异常?
有关信息:我有一个名为 T_TRADE_KEY 的表,其中有一列 TRADE_KEY_ID。

谢谢

4

1 回答 1

3

查看 liquibase 代码并根据您提供的堆栈跟踪 liquibase 正在references="T_TRADE_KEY"使用正则表达式检查 : ([\\w\\._]+)\\(([\\w_]+)\\)。虽然这不匹配,但会抛出您得到的错误。

正则表达式需要带括号的东西。

所以我猜是这样的:

references="T_TRADE_KEY(TRADE_KEY_ID)"

应该管用。

该属性foreignKeyName不是外键的列名,而只是外键的名称。

也许<constraint>标签上的文档也有帮助。

于 2013-06-26T09:29:37.263 回答