简体   繁体   中英

Spring Boot with JPA does not generate tables in the database

When I run the project, does not create tables in MySQL.

I tried to change the spring.jpa.hibernate.ddl-auto = update to create-drop and also does not to create.

No error appears in the log.

My class

@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity(name = "tb_user")
public class User {

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Long id;

 @Column(length = 75, nullable = false)
 private String name;

 @Column(length = 75, nullable = false, unique = true)
 private String email;

 @Column(length = 100, nullable = false)
 private String password;
 }

My pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

my application.properties

spring.datasource.url=jdbc:mysql://localhost:3307/db_spring?useTimezone=true&serverTimezone=UTC
spring.datasource.username=sa
spring.datasource.password=1234567
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

Try adding

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

also check you are using @EnableAutoConfiguration and entity classes are in same package or subpackage

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