Flyway没有创建正确的表格

时间:2016-12-08 01:20:22

标签: java jpa spring-boot vaadin flyway

我一直在尝试使用vaadin,spring boot和flyway创建一个程序。但是当我尝试访问程序时,JPA没有读取正确的数据库。以下是我一直关注的示例:https://github.com/mstahv/spring-data-vaadin-crud

GameTemplate.java

@Entity
@Table(name = "GameTemplate")
public class GameTemplate implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

@NotNull(message = "Part number is required")
private String partNum;

private String gameName;
private Double gameCost;
private Double ticketCost;
private Integer numTickets;
private Integer idealGross;
private Integer idealPrizes;
private Integer idealNet;
//omitted

public GameTemplate(){
    //JPA
}
//getters/setters

GameTemplateRepo.java

public interface GameTemplateRepository extends JpaRepository<GameTemplate,    Long> {

List<GameTemplate> findAllBy(Pageable pageable);

List<GameTemplate> findByPartNumLikeIgnoreCase(String partnumFilter);
}

资源/ db.migration / V1__Initial_Schema.sql

CREATE TABLE GameTemplate (
`id` bigint auto_increment,
`partNum` varchar(12) NOT NULL,
`gameName` varchar(50) DEFAULT NULL,
`gameCost` double DEFAULT '0',
`ticketCost` double DEFAULT NULL,
`numTickets` int(11) DEFAULT NULL,
`idealGross` mediumint(9) DEFAULT NULL,
`idealPrizes` mediumint(9) DEFAULT NULL,
`idealNet` mediumint(9) DEFAULT NULL,
//omitted, inserted some data as well.

堆栈:

2016-12-07 20:14:25.818  INFO 18236 --- [  restartedMain] o.f.core.internal.util.VersionPrinter    : Flyway 3.2.1 by Boxfuse
2016-12-07 20:14:25.946  INFO 18236 --- [  restartedMain] o.f.c.i.dbsupport.DbSupportFactory       : Database: jdbc:h2:mem:testdb (H2 1.4)
2016-12-07 20:14:26.057  INFO 18236 --- [  restartedMain] o.f.core.internal.command.DbValidate     : Validated 1 migration (execution time 00:00.082s)
2016-12-07 20:14:26.066  INFO 18236 --- [  restartedMain] o.f.c.i.metadatatable.MetaDataTableImpl  : Creating Metadata table: "PUBLIC"."schema_version"
2016-12-07 20:14:26.080  INFO 18236 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Current version of schema "PUBLIC": << Empty Schema >>
2016-12-07 20:14:26.080  INFO 18236 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version 1 - Initial Schema
2016-12-07 20:14:26.095  INFO 18236 --- [  restartedMain] o.f.core.internal.command.DbMigrate      : Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.030s).

在localhost上访问时,一切似乎都很好:

2016-12-07 20:14:29.680 ERROR 18236 --- [nio-8090-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : Table "GAME_TEMPLATE" not found; SQL statement:

世界上哪里可以获得&#34; GAME_TEMPLATE&#34;?

1 个答案:

答案 0 :(得分:0)

这是因为Spring默认使用Game_Template,它使用下划线分割驼峰案例名称。有关更多帮助,请参阅this

或者您可以将文件 V1__Initial_Schema.sql 中的表名更改为import { Component} from '@angular/core'; @Component({ selector: 'myCuteComponent', templateUrl: ` <h1>yoO World</h1> <input [(ngModel)]="cuteValue" (ngModelChange)="onInput($event)"> ` }) export class MyCuteComponent { onInput(value) { console.log(value); } }