简体   繁体   English

java.sql.SQLException:字段“participant_one_fk_id”没有默认值

[英]java.sql.SQLException: Field 'participant_one_fk_id' doesn't have a default value

I am having a problem creating a match with two members.我在创建与两个成员的匹配时遇到问题。 I cannot save participants to the match.我无法将参与者保存到比赛中。 Perhaps the problem is that do i use two one-to-one anatations in my project?也许问题是我在我的项目中使用了两个一对一的 anatations 吗?

 @Entity
    @Table(name = "mach")
    public class TournamentMatch {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "mach_id")
    private int id;

    private LocalDate startTime;

    private LocalDate finischTime;

    private BigDecimal scores;

    @ManyToOne
    @JoinColumn(name = "tournament_fk_id")
    private Tournament tournament;

    @OneToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE})
    @JoinColumn(name = "participant_two_fk_id")
    private Participant participantTwo;

    @OneToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE})
    @JoinColumn(name = "participant_one_fk_id")
    private Participant participantOne;

    public TournamentMatch() {
    }

class participant match班级参加比赛

@Entity
public class Participant {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "participant_id")
    private int id;

    @NotNull
    @Column(name = "nick_name")
    private String nickName;

    public Participant() {
    }
...gets,sets

i am trying to save to the repository我正在尝试保存到存储库

  @Override
    public void save(TournamentMatch match) {
        tournamentMatchRepository.save(match);
    }

this is my JSON request这是我的 JSON 请求

 {
    "id": 0,
    "startTime": "2018-10-10",
    "finischTime": "2018-10-11",
    "scores": "3",
  
    
   "tournament":{
   "id": 0,
   "name": "ChempionsLigue1"
 },
      "participantOne":{
   "id": 0,
   "nickName": "PlayerOne"
  
 },
  "participantTwo":{
   "id": 0,
   "nickName": "PlayerTwo"
  
 }
 }

writes an error写一个错误

java.sql.SQLException: Field 'participant_one_fk_id' doesn't have a default value

AUTO_INCREMENT PRIMARY KEY available in all classes AUTO_INCREMENT PRIMARY KEY 适用于所有类

It seems that your column participant_one_fk_id does not have a default value.似乎您的列参与者_one_fk_id 没有默认值。 Try something like this尝试这样的事情

  1. Add a default value to the column participant_one_fk_id Using -将默认值添加到列参与者_one_fk_id 使用 -

    ALTER TABLE 'xxx' ALTER 'participant_one_fk_id' SET DEFAULT NULL ALTER TABLE 'xxx' ALTER 'participant_one_fk_id' SET DEFAULT NULL

( I think the only first step will do the trick, try right after first step ) (我认为唯一的第一步可以解决问题,请在第一步之后尝试)

  1. Supply some value to the participant_one_fk_id' column during insertion.在插入期间为participant_one_fk_id'列提供一些值。

  2. Add an auto increment to the column and add a primary key to it using the code :-向列添加自动增量并使用以下代码为其添加主键:-

    ALTER TABLE 'xxx' CHANGE 'participant_one_fk_id' 'participant_one_fk_id' INT(10)AUTO_INCREMENT PRIMARY KEY; ALTER TABLE 'xxx' CHANGE 'participant_one_fk_id' 'participant_one_fk_id' INT(10)AUTO_INCREMENT PRIMARY KEY;

If it complains about something regarding integer I know that "width" or whatever is deprecated so (10) might won't be required, but try with it first.如果它抱怨有关整数的某些内容,我知道“宽度”或任何已弃用的内容,因此可能不需要 (10),但请先尝试使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:字段没有默认值 - java.sql.SQLException: Field doesn't have a default value Java 实体 java.sql.SQLException:字段“id”没有默认值 - Java Entity java.sql.SQLException: Field 'id' doesn't have a default value Spring Boot java.sql.SQLException:字段“id”没有默认值 - Spring Boot java.sql.SQLException: Field 'id' doesn't have a default value java.sql.SQLException:字段“id”没有默认值 - java.sql.SQLException: Field 'id' doesn't have a default value java.sql.SQLException:字段“register_id”没有默认值 - java.sql.SQLException: Field 'register_id' doesn't have a default value 具有一对多关系映射的“ java.sql.SQLException:字段'id_parent'没有默认值” - “java.sql.SQLException: Field 'id_parent' doesn't have a default value” with one-to-many relationship mapping java.sql.SQLException: 字段 'supplier_id' 没有默认值 - java.sql.SQLException: Field 'supplier_id' doesn't have a default value java.sql.SQLException:字段“ client_id”没有默认值 - java.sql.SQLException: Field 'client_id' doesn't have a default value java.sql.SQLException:“字段‘voc_id’没有默认值”。 使用 Spring JPA - java.sql.SQLException: 'Field 'voc_id' doesn't have a default value'. using Spring JPA java.sql.SQLException:field id 没有默认值 - java.sql.SQLException:field id does not have a default value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM