title: Setting a Foreign Key using ebean in Play Framework
body: <p>I have two model classes </p>
  
  <h2>CustomerAccount</h2>
  
  <pre><code>@Entity
  public class CustomerAccount extends Model {
      @Id
      @Column(columnDefinition = "int(11)")
      public int customer_id;
      @Column(columnDefinition = "varchar(50) not null unique")
      public String customer_email;
      @Column(columnDefinition = "varchar(50) not null")
      public String password;
  }
  </code></pre>
  
  <h2>Customer</h2>
  
  <pre><code>@Entity
  public class Customer extends Model {
  
      @Column(columnDefinition = "int(11) unique")
      public int customer_id = 6;
      @Column(columnDefinition = "varchar(50) not null")
      public String customer_fname;
      @Column(columnDefinition = "varchar(50) not null")
      public String customer_lname;
      @Column(columnDefinition = "varchar(50) unique not null")
      public String email = "";
  }
  </code></pre>
  
  <p>Now I want to add a foriegn key in table CustomerAccount reference to Customer table like: -</p>
  
  <p>Foreign Key (customer_email) references Customer(email);</p>
  
  <p>Please tell me how to do this...</p>
  
  <hr>
  
  <p>while running the following code to add details to Customer Account</p>
  
  <pre><code>public static Result addPerson() {
          String result = "ok";
          CustomerAccount Customer_Account = Form.form(CustomerAccount.class).bindFromRequest().get();
          List&lt;CustomerAccount&gt; personsDetails = new Model.Finder(String.class, CustomerAccount.class).all();
  
          for (CustomerAccount product : personsDetails) {
              if (product.customer.email.equals(Customer_Account.customer.email) ) {
                  result = "";
              }
          }
          if (result.equals("ok")) {
              Customer_Account.save();
              return ok("New Customer Account Created");
          }else{
              return ok("Customer with same email Already Exists");
          }
  
      }
  </code></pre>
  
  <p>I am getting this error</p>
  
  <pre><code>[PersistenceException: ERROR executing DML bindLog[] error[Column 'customer_email' cannot be null]]
  </code></pre>