title: Entity Framework error when creating foreign keys
body: <p>I'm attempting to use migrations to generate my EF database, but I'm getting a couple of errors when I'm executing the <code>update-database</code> command.</p>
  
  <p>Error 1</p>
  
  <pre><code>Failed executing DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  CREATE TABLE [Occupier] (
      [OccupierId] int NOT NULL IDENTITY,
      [Title] int NOT NULL,
      [FirstName] nvarchar(32) NULL,
      [LastName] nvarchar(32) NULL,
      [Dob] datetime2 NOT NULL,
      [Relationship] nvarchar(32) NULL,
      CONSTRAINT [PK_Occupier] PRIMARY KEY ([OccupierId]),
      CONSTRAINT [FK_Occupier_Property_OccupierId] FOREIGN KEY ([OccupierId]) REFERENCES [Property] ([PropertyId]) ON DELETE CASCADE
  );
  </code></pre>
  
  <p>Error 2</p>
  
  <blockquote>
    <p>Cascading foreign key 'FK_Occupier_Property_OccupierId' cannot be created where the referencing column 'Occupier.OccupierId' is an identity column.
        Could not create constraint or index. See previous errors.</p>
  </blockquote>
  
  <p>From what I can see I have my tables set up correctly, but there's obviously something missing which I can't see. I'll post the code for the tables below and hopefully someone can see what I'm missing. </p>
  
  <p>For clarity; a <code>SolicitorInstruction</code> has a <code>Property</code> object, which may contain a number of <code>Occupiers</code>.</p>
  
  <p>I'm also not sure about the way <code>[ForeignKey("string")]</code> works. Is this saying "this is a foreign key to primary key "string"? or "string" is a foreign key?</p>
  
  <p>SolicitorInstruction</p>
  
  <pre><code>public class SolicitorInstruction
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int SolicitorInstructionId { get; set; }
          public InstructionTypes InstructionType { get; set; }
          public int ApplicationId { get; set; }
          public DateTime DateLogged { get; set; }
          [ForeignKey("AdditionalInformationId")]
          public AdditionalInformation AdditionalInformation { get; set; }
          [ForeignKey("BorrowerBankId")]
          public BorrowerBank BorrowerBank { get; set; }
          [ForeignKey("BrokerId")]
          public Broker Broker { get; set; }
          [ForeignKey("PropertyId")]
          public Property Property { get; set; }
          [ForeignKey("SolicitorId")]
          public Solicitor Solicitor { get; set; }
          [ForeignKey("BorrowerId")]
          public List&lt;Borrower&gt; Borrower { get; set; }
          [ForeignKey("CurrentLenderId")]
          public List&lt;CurrentLender&gt; CurrentLender { get; set; }
      }
  </code></pre>
  
  <p>Property</p>
  
  <pre><code>[Table("Property")]
  public partial class Property
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int PropertyId { get; set; }
  
      [StringLength(8)]
      public string ReferenceNumber { get; set; }
      [StringLength(4)]
      public string CaseOwner { get; set; }
      public int AmountBorrowed { get; set; }
      [ForeignKey("SecurityAddressId")]
      public Address Security { get; set; }
      [ForeignKey("CorrespondenceAddressId")]
      public Address Correspondence { get; set; }
      [ForeignKey("OccupierId")]
      public List&lt;Occupier&gt; Occupier { get; set; }
      public TenureTypes Tenure { get; set; }
      public JurisdictionTypes Jurisdiction { get; set; }
      public FunderTypes Funder { get; set; }
  
      public Property()
      {
          Occupier = new List&lt;Occupier&gt;();
      }
  }
  </code></pre>
  
  <p>Occupier</p>
  
  <pre><code>[Table("Occupier")]
      public partial class Occupier
      {
          [Key]
          [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
          public int OccupierId { get; set; }
          public Honorifics Title { get; set; }
          [StringLength(32)]
          public string FirstName { get; set; }
          [StringLength(32)]
          public string LastName { get; set; }
          public DateTime Dob { get; set; }
          [StringLength(32)]
          public string Relationship { get; set; }
  
      }
  </code></pre>