I am try to make simple spring boot api and generate table automaticaly.But whenI call the api i get an error that tha table not exist ? my application.properties
spring.datasource.username=root
spring.datasource.password=123
logging.level.org.springframework.security=TRACE
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.formate_sql=true
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
server.error.include-message=always```
CodePudding user response:
You configuration won't generate any tables automatically due to non-emdedded database (MySQL). Therefore you must configure ddl-auto explicitly.
spring.jpa.hibernate.ddl-auto=update
OR
spring.jpa.hibernate.ddl-auto=create-drop
Have a look at Spring Docs for more details.
CodePudding user response:
To generate Tables automatically with spring boot 1. First set your POJO class with the @Entity annotation. 2. Use the bellow Properties and Run the application tables will be created automatically.
spring.datasource.url=jdbc:mysql://localhost:3306/Your DB name
spring.datasource.username= username
spring.datasource.password= password
spring.jpa.hibernate.ddl-auto=update
The four configurations enough to create tables automatically.
CodePudding user response:
To generate your tables you need to implement this lines to your application.properties:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/YOURSCHEMA
spring.datasource.username=YOURUSER
spring.datasource.password= YOURPASSWORD
spring.datasource.driver-class-name =com.mysql.jdbc.Driver
spring.jpa.show-sql: true
You also need to add some dependencies to run the project like the connector to your db, for example I use MySqlConnector. If you have changed this lines and does not work provide me more info about what you want to do by replying this thread.