Search code examples
javamysqldatabaseplayframeworkebean

Error appear while trying create new database play framework ebean mysql


I have model orders and it gives me an error when I am trying to apply it:

Database 'default' is in an inconsistent state! An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.

While trying to run SQL script below, we got the following error:

You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use 
near 'order ( id bigint auto_increment not null, description ' 
at line 1 [ERROR:1064, SQLSTATE:42000], while trying to run this SQL script:

The script:

package models;

import play.data.format.Formats;
import play.db.ebean.Model;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
public class Order extends Model{

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



    @Column(columnDefinition="TEXT")
    public String description;


    public  Boolean status;


    @Formats.DateTime(pattern="dd/MM/yyyy")
    public Date dueDate = new Date();

    @Formats.DateTime(pattern="dd/MM/yyyy")
    public Date dueDate2 = new Date();


    public Double total;




    public Order(){
        //this.name=name;
        //.description=description;
    }

    public static Finder<Long, Order> find=new Finder<Long, Order>(Long.class, Order.class);


    public static List<Order> findAll() {
        return find.all();
    }


    public static void create(String name,String description){
        Order newMenu=new Order();
        newMenu.save();
    }

    public static void update(Long id,String name,String description){
        Order restaurant= Order.find.ref(id);
        System.out.println("id:"+id);
        //restaurant.name=name;
        /*restaurant.description=description;
        restaurant.update();*/


    }
    public static void delete(Long id){
        find.ref(id).delete();
    }
} 

SQl:

# --- Rev:1,Ups - 50058ce

create table category (
id                        bigint auto_increment not null,
name                      varchar(255),
description               TEXT,
menu_id                   bigint,
parent_category           bigint,
constraint pk_category primary key (id))
;

create table menu (
id                        bigint auto_increment not null,
name                      varchar(255),
description               TEXT,
constraint pk_menu primary key (id))
;

create table menu_item (
id                        bigint auto_increment not null,
title                     varchar(255),
short_title               varchar(255),
description               TEXT,
price_original            integer,
price_for_sale            integer,
image                     varchar(255),
status                    tinyint(1) default 0,
cook_time                 integer,
prep_instruction          TEXT,
category_id               bigint,
unit                      ENUM('кг','л','штук'),
constraint ck_menu_item_unit check (unit in ('gramm','litr','item')),
constraint pk_menu_item primary key (id))
;

create table order (
id                        bigint auto_increment not null,
description               TEXT,
status                    tinyint(1) default 0,
due_date                  datetime,
due_date2                 datetime,
total                     double,
constraint pk_order primary key (id))
;

create table order_type (
id                        integer auto_increment not null,
title                     varchar(255),
description               TEXT,
status                    varchar(255),
constraint pk_order_type primary key (id))
;

create table restaurant (
id                        bigint auto_increment not null,
name                      varchar(255),
description               TEXT,
image                     varchar(255),
contact                   varchar(255),
address                   TEXT,
constraint pk_restaurant primary key (id))
;

create table restaurant_section (
id                        bigint auto_increment not null,
name                      varchar(255),
description               TEXT,
image                     varchar(255),
constraint pk_restaurant_section primary key (id))
;

create table smeny (
id                        bigint auto_increment not null,
name                      varchar(255),
opened                    TEXT,
closed                    TEXT,
constraint pk_smeny primary key (id))
;

create table user_test (
email                     varchar(40) not null,
password                  varchar(255),
name                      varchar(255),
role                      integer,
constraint pk_user_test primary key (email))
;

alter table category add constraint fk_category_menu_1 foreign key (menu_id) references menu (id) on delete restrict on update restrict;
create index ix_category_menu_1 on category (menu_id);
alter table category add constraint fk_category_parent_category_2 foreign key (parent_category) references category (id) on delete restrict on update restrict;
create index ix_category_parent_category_2 on category (parent_category);
alter table menu_item add constraint fk_menu_item_category_3 foreign key (category_id) references category (id) on delete restrict on update restrict;
create index ix_menu_item_category_3 on menu_item (category_id);

Solution

  • order is a reserved word in MySQL check. So you better change the name of your table.