简体   繁体   中英

Spring boot exception error executing ddl

Good day, I suppose

I was learning spring boot and working on small project to expand my knowledge.

Somehow I got exception while launching spring boot app, that I don't know how to solve.

Here is the part of exception message

Hibernate: alter table token add constraint FK79keudebybjlldk2o4i0nwqev foreign key (user_user_id) references user
2022-05-18 12:01:20.531  WARN 9092 --- [           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table token add constraint FK79keudebybjlldk2o4i0nwqev foreign key (user_user_id) references user" via JDBC Statement

I don't know exactly where is the trouble so here is the link to repository. As far as I know everything was expected to work safe and sound ;(

githubRepo

Spring boot probably was configured to have spring.jpa.hibernate.ddl-auto=update meaning it will update the schema to match the domain layer of spring application when needed.

Considering that the schema already contained some data (table records), Spring tried to update a table to have a constraint, but that constraint was not respected by the existing data so the DDL failed.

Cleaning the data of the mentioned table would probably allow spring to execute the DDL script to apply the aforementioned constraint.

Otherwise you can switch to spring.jpa.hibernate.ddl-auto=create where Spring will first remove all tables from database which would mean removal of existing data as well, and then recreate the schema. This would have as effect that no previous data would violate the constraint. Hence spring will be able to move forward with DDL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM