title: Code First: Optional One to One Relationship
body: <p>I have two entity models, Series and Fixture. A series may have a fixture and a fixture may have a series. Here are simplified version of both entities.</p>
  
  <p>Series.cs</p>
  
  <pre><code>public class Series
  {
      public int Id { get; set; }
      public int? FixtureId { get; set; }
      public virtual Fixture Fixture { get; set; }
  }
  </code></pre>
  
  <p>Fixture.cs</p>
  
  <pre><code>public class Fixture
  {
      public int Id { get; set; }
      public int? SeriesId { get; set; }
      public virtual Series Series { get; set; }
  }
  </code></pre>
  
  <p>and then my fluent is as follows:</p>
  
  <pre><code>modelBuilder.Entity&lt;Series&gt;()
              .HasOptional(a =&gt; a.Fixture)
              .WithOptionalPrincipal(a =&gt; a.Series);
  </code></pre>
  
  <p>I dont know if I need to mark my properties with certain annotations or if my fluent config is incorrect.</p>
  
  <p>With this particular example I am getting the following error when I try to run update-database -verbose</p>
  
  <p>The index 'IX_Series_Id' is dependent on column 'Series_Id'.
  ALTER TABLE DROP COLUMN Series_Id failed because one or more objects access this column.</p>
  
  <p>Current migration code:</p>
  
  <pre><code>    public override void Up()
      {
          DropIndex("dbo.Series", new[] { "FixtureId" });
          RenameColumn(table: "dbo.Fixture", name: "FixtureId", newName: "Series_Id");
          CreateIndex("dbo.Fixture", "Series_Id");
      }
  
      public override void Down()
      {
          DropIndex("dbo.Fixture", new[] { "Series_Id" });
          RenameColumn(table: "dbo.Fixture", name: "Series_Id", newName: "FixtureId");
          CreateIndex("dbo.Series", "FixtureId");
      }
  </code></pre>