简体   繁体   中英

Play Framework evolutions using unsupported syntax for MySQL

I started a project with Play Framework 2.4 including Ebean ORM and using MySql Server 5.5.

As Play docs describes, it possible to generate the database from objects and it is working as expected. But when I tried to insert a Timestamp I got a problem because Play is using a newer mysql syntax that is not supported by my server.

Here is my model:

@ManyToOne
@Column(name = "user_send_id")
private User userSendReq;

@ManyToOne
@Column(name = "user_request_id")
private User userGetReq;

@CreatedTimestamp
@Column(name = "date_request")
private Timestamp whenRequest;

@UpdatedTimestamp
@Column(name = "date_friends")
private Timestamp whenFriends;

private boolean request;

And this is the MySQL code Play generates for me:

create table friends (
user_send_req_id          bigint,
user_get_req_id           bigint,
request                   tinyint(1) default 0,
date_request              datetime(6) not null,
date_friends              datetime(6) not null)
;

When I try to apply the evolution to the server I got the error below:

Error Code: 1064. 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 '(6) not null, date_friends datetime(6) not null)' at line 5

Is there a way to tell Play to generate the SQL Evolution files just with datetime() and not with datetime(6) ?

This is more related to Ebean than with Play, since play uses Ebean to generate the DDL. To solve this, you can explicitly set the SQL type while mapping your models. Just use the columnDefinition parameter for the @Column annotation:

@CreatedTimestamp
@Column(name = "date_request", columnDefinition = "datetime")
private Timestamp whenRequest;

@UpdatedTimestamp
@Column(name = "date_friends", columnDefinition = "datetime")
private Timestamp whenFriends;

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