为什么我得到 "Referential integrity constraint violation" with jpa Derived Identifier
Why do I get "Referential integrity constraint violation" with jpaDerivedIdentifier
使用Jhipster 从jdl 文件生成应用程序后,应用程序启动时出现以下错误。当我在与用户 table.
的 OneToOne 关系上使用 jpaDerivedIdentifier 时,我才遇到这个问题
liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20201128181606_added_entity_constraints_RegistrationOrder.xml::20201128181606-2::jhipster:
Reason: liquibase.exception.DatabaseException: Referential integrity constraint violation: "FK_REGISTRATION_ORDER_STUDENT_ID: PUBLIC.REGISTRATION_ORDER FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.STUDENT(ID)"; SQL statement:
ALTER TABLE PUBLIC.registration_order ADD CONSTRAINT fk_registration_order_student_id FOREIGN KEY (student_id) REFERENCES PUBLIC.student (id) [23506-200] [Failed SQL: (23506) ALTER TABLE PUBLIC.registration_order ADD CONSTRAINT fk_registration_order_student_id FOREIGN KEY (student_id) REFERENCES PUBLIC.student (id)]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:646)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314)
at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet[=11=](AsyncSpringLiquibase.java:93)
at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable(ExceptionHandlingAsyncTaskExecutor.java:78)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
我的 JDL 是:
entity Student {
birthDate LocalDate
nickName String maxlength(50)
}
entity RegistrationOrder{
paymentAmount BigDecimal required min(0)
materialFee BigDecimal required min(0)
placedDate Instant required
}
relationship OneToOne {
Student{user(login) required} to User with jpaDerivedIdentifier
}
relationship ManyToOne {
RegistrationOrder{student required} to Student
}
如果我删除了“with jpaDerivedIdentifier”,Jhipster 应用程序启动时没有错误。有什么想法吗?
可能是因为 Liquibase 已经从 CSV 加载了一些数据,这些数据违反了您在迁移中添加的外键。更改 CSV 文件中的数据或更改迁移顺序。
您与用户共享 ID 的事实当然没有帮助,因为用户 table 是在第一次迁移时创建和加载的。
使用Jhipster 从jdl 文件生成应用程序后,应用程序启动时出现以下错误。当我在与用户 table.
的 OneToOne 关系上使用 jpaDerivedIdentifier 时,我才遇到这个问题liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20201128181606_added_entity_constraints_RegistrationOrder.xml::20201128181606-2::jhipster:
Reason: liquibase.exception.DatabaseException: Referential integrity constraint violation: "FK_REGISTRATION_ORDER_STUDENT_ID: PUBLIC.REGISTRATION_ORDER FOREIGN KEY(STUDENT_ID) REFERENCES PUBLIC.STUDENT(ID)"; SQL statement:
ALTER TABLE PUBLIC.registration_order ADD CONSTRAINT fk_registration_order_student_id FOREIGN KEY (student_id) REFERENCES PUBLIC.student (id) [23506-200] [Failed SQL: (23506) ALTER TABLE PUBLIC.registration_order ADD CONSTRAINT fk_registration_order_student_id FOREIGN KEY (student_id) REFERENCES PUBLIC.student (id)]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:646)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314)
at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet[=11=](AsyncSpringLiquibase.java:93)
at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable(ExceptionHandlingAsyncTaskExecutor.java:78)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
我的 JDL 是:
entity Student {
birthDate LocalDate
nickName String maxlength(50)
}
entity RegistrationOrder{
paymentAmount BigDecimal required min(0)
materialFee BigDecimal required min(0)
placedDate Instant required
}
relationship OneToOne {
Student{user(login) required} to User with jpaDerivedIdentifier
}
relationship ManyToOne {
RegistrationOrder{student required} to Student
}
如果我删除了“with jpaDerivedIdentifier”,Jhipster 应用程序启动时没有错误。有什么想法吗?
可能是因为 Liquibase 已经从 CSV 加载了一些数据,这些数据违反了您在迁移中添加的外键。更改 CSV 文件中的数据或更改迁移顺序。
您与用户共享 ID 的事实当然没有帮助,因为用户 table 是在第一次迁移时创建和加载的。