title: Spring Boot: Why am I not able to insert entry although I added the "NO_CONSTRAINT" attribute in the @JoinColumn annotation?
body: <p>I am trying to insert an entry into the &quot;txt_auth_a&quot; table which has auto_inc_id as the primary key and &quot;account_id&quot; as the foriegn key, thus there's a one-to-one relationship between account_id and auto_inc_id. The auto_inc_id is also the primary key for the &quot;txt_account&quot; table.</p>
  <p>Text Account Entity:</p>
  <pre><code>@Entity
  @Table(name=&quot;txt_account&quot;)
  public class TextAccount 
  {
      
      //
      
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      //@Column(name=&quot;auto_inc_id&quot; , nullable=false, updatable=false, insertable=false)
      @OneToOne(mappedBy=&quot;TextAuthA.class&quot;)
      @JoinColumn(name=&quot;auto_inc_id&quot;,nullable=false , foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
      private int auto_inc_id;
  </code></pre>
  <p>txt_auth_a entity:</p>
  <pre><code>@Entity
  @Table(name=&quot;txt_auth_a&quot;)
  public class TextAuthA 
  {
      //
      
      //@JoinColumn(name=&quot;auto_inc_id&quot;,nullable=false , foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name=&quot;auto_inc_id&quot; , nullable=false)
      private int auto_inc_id;
      
      //@Column(name=&quot;account_id&quot; , nullable=false)
      @OneToOne(targetEntity = TextAccount.class, cascade=CascadeType.ALL)
      @JoinColumn(referencedColumnName = &quot;auto_inc_id&quot;, foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT), updatable=false, insertable=false)
      private int account_id;
  </code></pre>
  <p>The query I run in my DAO for txt_auth_a is:</p>
  <pre><code>@Modifying
      @Transactional
      @Query(value=&quot;INSERT INTO txt_auth_a (account_id, username, email, password) VALUES(:accid , :username , :email , :password )&quot;,
              nativeQuery=true)
      public void signup(int accid, String username, String email, String password);
  </code></pre>
  <p>I am getting the an error of foriegn key constraint although I say @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)</p>
  <pre><code>java.sql.SQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`megamadz`.`txt_auth_a`, CONSTRAINT `txt_auth_a_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `txt_account` (`auto_inc_id`) ON DELETE CASCADE ON UPDATE CASCADE)
  </code></pre>