当前位置: 首页 > 知识库问答 >
问题:

SQL语句“CREATE TABLE TRIP……”中存在语法错误

暨正真
2023-03-14

错误消息:

[错误]运行得测试:1,失败:0,错误:1,跳过得:0,运行得时间:3.003s<<<失败!-在org.studentnr.backend.service.userserviceTest[错误]org.studentnr.backend.service.userserviceTest.testCreateUser所用时间:0.004s<<<错误!java.lang.IllegalStateException:未能加载ApplicationContext,原因是:org.SpringFramework.Beans.Factory.BeanCreationException:创建类路径资源[org/SpringFramework/boot/autocigure/flyway/flywayAutoConfiguration$flywayConfiguration.class]中定义的名为“Flyway初始化器”的bean时出错:调用init方法失败;嵌套异常为org.flywaydb.core.internal.command.dbmigrate$flywaymigrateexception:迁移v1.0__createdb.sql失败

SQL状态:42000错误代码:42000消息:SQL语句“CREATE TABLE TRIP(ID BIGINT默认生成为标识,标题VARCHAR(255)不为NULL,说明VARCHAR(255),成本整数不为NULL,位置VARCHAR(124)不为NULL,出发日期不为NULL,返回日期不为NULL,主键(ID)”中存在语法错误

我的flyway sql脚本:

create sequence hibernate_sequence start with 1 increment by 1;

create table user_roles (user_email varchar(255) not null, roles varchar(255));

create table users (email varchar(255) not null, firstname varchar(50) not null, middle_name 
varchar(50), surename varchar(50) not null, password varchar(255) not null, address 
varchar(128) not null, postal_code varchar(124) not null, enabled boolean not null, primary 
key (email));

create table purchase (id bigint generated by default as identity, booked_date date not 
null, user_email varchar(255) not null, trip_id bigint not null, primary key (id));

create table trip (id bigint generated by default as identity, title varchar(255) not null, 
description varchar(255), cost integer not null, location varchar(128) not null, departure 
date not null, returning date not null, primary key (id))


alter table user_roles add constraint FKs9rxtuttxq2ln7mtp37s4clce foreign key (user_email)         
references users;

alter table purchase add constraint FKlqrv1aj0pon999jbi5esfpe4k foreign key (user_email) 
references users;

以下是我的旅行实体:

package org.studentnr.backend.entities;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.time.LocalDate;

@Entity
public class Trip {

 @Id @GeneratedValue
 private Long id;

 @NotBlank
 @Size(max=255)
 private String title;

 //@NotBlank //TODO: Can be blank???
 @Size(max=255)
 private String description;

 //@Min(0) TODO: remember to add 'check (cost>0)' to flyway to avoid using negative values
 @NotNull
 private Integer cost;

 @NotBlank
 @Size(max = 124)
 private String location;

 @NotNull
 @Future   
 private LocalDate departure;

 @NotNull
 @Future  
 private LocalDate returning;



public Trip(){
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public int getCost() {
    return cost;
}

public void setCost(int cost) {
    this.cost = cost;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public LocalDate getDepartureDate() {
    return departure;
}

public void setDepartureDate(LocalDate departureDate) {
    this.departure = departureDate;
}

public LocalDate getReturnDate() {
    return returning;
}

public void setReturnDate(LocalDate returnDate) {
    this.returning = returnDate;
}



}

共有1个答案

归松
2023-03-14

脚本中有两个错误:

  1. CREATE TRIP语句的末尾缺少
  2. returning是保留关键字。您将不得不引用它“返回”日期-但如果您找到一个不同的名称,从长远来看会更容易。

如果纠正了这两件事,脚本就可以工作了

 类似资料:
  • 我在尝试使用flyway和hibernate为PostgresSql创建表时遇到语法错误的问题。Trip类与其他类没有关系(还没有)。我已经成功地为其他两个类创建了购买和用户,但是这个只是给出了错误。 错误信息: [错误]测试运行:1,失败:0,错误:1,跳过:0,所用时间:3.003秒 SQL状态:42000错误代码:42000消息:SQL语句“CREATE TABLE TRIP(ID BIGI

  • 我从Spring Boot进行了升级 它创建序列,但不创建任何表。查看跟踪,它显示了创建表中的语法错误 SQL:SQL 语句中的语法错误(一个示例): 事实上,检查qith H2控制台或SQl linter它将“IDENTITY[*]”标记为错误,否则它将在H2中工作。 第二次尝试也是失败的。我把 并将Spring文档 https://docs.spring.io/spring-batch/doc

  • 我正在尝试创建h2 DB模式。这是我的sql 我得到一个错误 原因:org。h2。jdbc。JdbcSQLSyntaxErrorException:SQL语句“创建扩展[*]如果不存在UUID_OSSP”中的语法错误;预期“或、强制、视图、别名、序列、用户、触发器、角色、模式、常量、域、类型、数据类型、聚合、链接、内存、缓存、本地、全局、临时、表、同义词、主、唯一、哈希、空间、索引”;SQL语句:

  • 我有一个 springboot 应用程序,我想将我的应用程序连接到 H2 数据库。下面是我的架构。 下面是我的应用程序属性。 但是,我面临以下问题: 由:org.h2.jdbc引起。JdbcSQLSyntaxErrorException:SQL语句“create table employee(id bigint not null auto_increment,email varchar(255),

  • 我是MySQL存储过程的新手。不知道为什么我会出现以下错误。请帮我调试一下。 1064年的今天,您的SQL语法出现错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在第3行的user_-username=@th'中使用near'作为该用户的id,该用户的全名 表名:user_master 用户id密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密码密

  • 目录 13.1. 数据定义语句 13.1.1. ALTER DATABASE语法 13.1.2. ALTER TABLE语法 13.1.3. CREATE DATABASE语法 13.1.4. CREATE INDEX语法 13.1.5. CREATE TABLE语法 13.1.6. DROP DATABASE语法 13.1.7. DROP INDEX语法 13.1.8. DROP TABLE语法