gpt4 book ai didi

grails - Grails db-migration dbm-db-doc脚本失败

转载 作者:行者123 更新时间:2023-12-02 14:30:47 27 4
gpt4 key购买 nike

我试图运行“dbm-db-doc”脚本。该脚本似乎无法正常运行,因为它在已执行的变更日志上失败了。这是更改:

changeSet(author: "Bernardo (generated)", id: "1436991688243-1") {
addColumn(tableName: "prepares_for_exam") {
column(name: "exam_id", type: "bigint")
}

grailsChange {
change {
sql.execute("UPDATE prepares_for_exam JOIN product ON prepares_for_exam.id = product.prepares_for_exam_id SET prepares_for_exam.exam_id = product.id")
}
rollback {
}
}

addNotNullConstraint(columnDataType: "bigint", tableName: "prepares_for_exam", columnName: "exam_id")
}

changeSet(author: "Bernardo (generated)", id: "1436991688243-32") {
dropColumn(columnName: "prepares_for_exam_id", tableName: "product")
}

并且在数据库中,此更改日志已标记为“已执行”

但是,在运行脚本时,脚本似乎要执行该更改日志并失败,因为“product.prepares_for_exam_id”列已被删除。

完整错误:
|Starting dbm-db-doc for database root @ jdbc:mysql://localhost:3306/xxx?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'product.prepares_for_exam_id' in 'on clause'
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2828)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2777)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:949)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:795)
at Script1$_run_closure1_closure2_closure35_closure36.doCall(Script1.groovy:10)
at grails.plugin.databasemigration.GrailsChange.generateStatements(GrailsChange.groovy:159)
at liquibase.change.AbstractChange.getAffectedDatabaseObjects(AbstractChange.java:208)
at liquibase.changelog.visitor.DBDocVisitor.visit(DBDocVisitor.java:95)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
at liquibase.Liquibase.generateDocumentation(Liquibase.java:740)
at DbmDbDoc$_run_closure1_closure2.doCall(DbmDbDoc:27)
at _DatabaseMigrationCommon_groovy$_run_closure2_closure11.doCall(_DatabaseMigrationCommon_groovy:59)
at grails.plugin.databasemigration.MigrationUtils.executeInSession(MigrationUtils.groovy:133)
at _DatabaseMigrationCommon_groovy$_run_closure2.doCall(_DatabaseMigrationCommon_groovy:51)
at DbmDbDoc$_run_closure1.doCall(DbmDbDoc:26)
at org.grails.ide.api.impl.GrailsConnectorImpl.executeCommand(GrailsConnectorImpl.java:160)
at org.grails.ide.eclipse.longrunning.process.GrailsProcess.run(GrailsProcess.java:130)
at org.grails.ide.eclipse.longrunning.process.GrailsProcess.main(GrailsProcess.java:93)
Error |
org.codehaus.groovy.grails.cli.ScriptExitException
Error |

所以我的问题是:

“dbm-db-doc”脚本中是否存在错误,或者我是否将变更集弄乱了?

最佳答案

我正在回答自己的问题,因为找到了解决方法:

尽管changeSet已经执行过,但似乎迁移插件每次都会继续执行“grailsChange”部分(我不知道为什么...欢迎回答!)

解决方法是不使用“grailsChange”,而使用常规的“sql”命令。解决方法是:

changeSet(author: "Bernardo (generated)", id: "1436991688243-1") {
addColumn(tableName: "prepares_for_exam") {
column(name: "exam_id", type: "bigint")
}

sql(""" UPDATE prepares_for_exam JOIN product ON prepares_for_exam.id = product.prepares_for_exam_id SET prepares_for_exam.exam_id = product.id """ )

addNotNullConstraint(columnDataType: "bigint", tableName: "prepares_for_exam", columnName: "exam_id")
}

关于grails - Grails db-migration dbm-db-doc脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31449082/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com