title: Error executing DDL "alter table score add constraint foreign key (enrollment_id) references enrollment (id)" via JDBC Statement
body: <p>I have an Enrollment class which has list of scores. I am trying to make a reference to the Score class but getting Error executing DDL &quot;alter table score add constraint ... foreign key (enrollment_id) references enrollment (id)&quot; via JDBC Statement Caused by: java.sql.SQLException: Failed to open the referenced table 'enrollment'. After running the application, the Score table is created in the database, but the Enrollment table is missing and enrollment_id column of the Score is not a foreign key. <strong>How can I solve this problem?</strong> I have tried to annotated with @Cache and to ignore the double creation of the table but it was not successfull. I am using MySQL.</p>
  <pre><code>@Entity
  @Table(name = &quot;enrollment&quot;)
  public class Enrollment {
      
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public int id;
      
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;student_id&quot;)
      public Student student;
      
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = &quot;date&quot;, nullable = false)
      public Date date;
  
      @Column(name = &quot;rank&quot;, nullable = false)
      public int rank;
      
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = &quot;specialty_id&quot;, referencedColumnName = &quot;id&quot;)
      public Specialty specialty;
      
      @Lob
      @Basic(fetch = FetchType.LAZY)
      @Column(name = &quot;files&quot;, columnDefinition = &quot;BLOB&quot;, nullable = false)
      private byte[] files;
      
      @OneToMany(mappedBy = &quot;enrollment&quot;, fetch = FetchType.LAZY)
      public List&lt;Score&gt; scores;
      
      @Column(name = &quot;state&quot;, length = 50, nullable = false)
      public String state;
     
  }
  
  @Entity
  @Table(name = &quot;score&quot;)
  public class Score {
      
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;
      
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = &quot;score_forming_object_id&quot;, referencedColumnName = &quot;id&quot;)
      private ScoreFormingObject scoreFormingObject;
      
      @Column(name = &quot;score&quot;, nullable = false)
      private double score;
      
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;enrollment_id&quot;)
      private Enrollment enrollment;
  }
  </code></pre>