1

I want to initialise schema using spring.jpa.generate-ddl=true and then populate using data.sql.

I tried it but it doesn't seem to work without schema.sql. Any suggesstions?

0

2 Answers 2

1

Add below config to your application.properties or application.yml file:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.initialization-mode=always

and use below config if you have data in the table:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.initialization-mode=always

See this question and its answer.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it already. But data.sql is executed before the table is created so it fails
I think I will go with db migrations instead
Hi Nasir, I have understood the root problem. It was not that it was not getting executed. You definitely helped me understanding the problem better.
1

spring.jpa.defer-datasource-initialization=true

will load your data.sql script after your table is generated.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.