我在播放1.2.4中的模型代码中遇到错误

时间:2015-03-30 16:16:50

标签: playframework playframework-1.x

该表未在我的数据库中创建。我编写的所有代码都是正确的但我找不到错误

21:21:56,433 ERROR ~ Unsuccessful: create table Student (id bigint not null auto_increment, Branch varchar(255), Div varchar(255), Mobile varchar(255), Name varchar(255), NumBacklogs integer not null, aggr double precision not null, email varchar(255), skID_SkID integer, primary key (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8
    21:21:56,433 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 'Div varchar(255), Mobile varchar(255), Name varchar(255), NumBacklogs integer no' at line 1
    21:21:56,743 ERROR ~ Unsuccessful: alter table Student add index FKF3371A1B229B2525 (skID_SkID), add constraint FKF3371A1B229B2525 foreign key (skID_SkID) references Skills (SkID)
    21:21:56,743 ERROR ~ Table 'placement2.student' doesn't exist

模型类

    package models;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;

    import play.data.validation.Required;

    import play.db.jpa.Model;


    @Entity
    public class Student extends Model{


        @Required
        public String Name;

        @Required
        public  String Branch;

        @Required
        public String Div;

        @Required
        public  String email;

        @Required
        public String Mobile;

        @Required
        public double aggr;

        @Required
        public int NumBacklogs;

        @ManyToOne
        @Required
        public Skills skID;



        public Student(String Name, String Branch, String Div, String email,                                     `           String Mobile,double aggr, int NumBacklogs,Skills skID){`
            this.Name = Name;
            this.Branch = Branch;
            this.Div = Div;
            this.email = email;
            this.Mobile = Mobile;
            this.aggr = aggr;
            this.NumBacklogs = NumBacklogs;
            this.skID = skID;


        }

    }

为什么我的数据库中没有创建表学生,尽管我已经编写了上面的代码?

1 个答案:

答案 0 :(得分:0)

Div是一个mysql保留字

你可以做到

@Required 
@Column(name="`div`")        //adding backticks
public String Div;

更改变量名称