title: EF Alter Table with FK error message
body: <p>I run in the following error message when I try to run the Seed method.</p>
  
  <blockquote>
    <p>System.Data.Entity.Infrastructure.DbUpdateException: An error occurred
    while updating the entries. See the inner exception for details. --->
    System.Data.Entity.Core.UpdateException: An error occurred while
    updating the entries. See the inner exception for details. --->
    System.Data.SqlClient.SqlException: The INSERT statement conflicted
    with the FOREIGN KEY constraint "FK_dbo.Movies_dbo.Genres_GenreId".
    The conflict occurred in database
    "C:\USERS\PATH\SOURCE\REPOS\MVCMOVIE\MVCMOVIE\APP_DATA\MOVIES.MDF",
    table "dbo.Genres", column 'Id'. The statement has been terminated.</p>
  </blockquote>
  
  <p>This is my Configuration.cs file</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>namespace MvcMovie.Migrations
  {
      using MvcMovie.Models;
      using System;
      using System.Data.Entity;
      using System.Data.Entity.Migrations;
      using System.Linq;
  
      internal sealed class Configuration : DbMigrationsConfiguration&lt;MvcMovie.Models.MovieDBContext&gt;
      {
          public Configuration()
          {
              AutomaticMigrationsEnabled = false;
              ContextKey = "MvcMovie.Models.MovieDBContext";
          }
  
          protected override void Seed(MvcMovie.Models.MovieDBContext context)
          {
              context.Genres.AddOrUpdate(i =&gt; i.Title,
                  new Genre
                  {
                      Title = "Comedy"
                  },
                  new Genre
                  {
                      Title = "Romantic"
                  });
  
              context.Ratings.AddOrUpdate(i =&gt; i.Title,
                 new Rating
                 {
                     Title = "General"
                 },
                 new MvcMovie.Models.Rating
                 {
                     Title = "Parentel guidence"
                 });
  
  
              context.Movies.AddOrUpdate(i =&gt; i.Title,
                  new Movie
                  {
                      Title = "When Harry Met Sally",
                      ReleaseDate = DateTime.Parse("1989-1-11"),
                      GenreId = 1,
                      RatingId = 1,
                      Price = 7.99M
                  },
  
                   new Movie
                   {
                       Title = "Ghostbusters ",
                       ReleaseDate = DateTime.Parse("1984-3-13"),
                       GenreId = 1,
                       RatingId = 1,
                       Price = 8.99M
                   },
  
                 }
             );
  
          }
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Rating and Genres are set to be FK in the Movie table. Has anyone had this type of error before?</p>
  
  <blockquote>
    <blockquote>
      <p>The statement has been terminated.    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
      Boolean breakConnection, Action<code>1 wrapCloseInAction)    at
      System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
      exception, Boolean breakConnection, Action</code>1 wrapCloseInAction)    at
      System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
      stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)    at
      System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
      SqlCommand cmdHandler, SqlDataReader dataStream,
      BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
      stateObj, Boolean&amp; dataReady)    at
      System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()    at
      System.Data.SqlClient.SqlDataReader.get_MetaData()    at
      System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
      RunBehavior runBehavior, String resetOptionsString, Boolean
      isInternal, Boolean forDescribeParameterEncryption)    at
      System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
      cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
      async, Int32 timeout, Task&amp; task, Boolean asyncWrite, Boolean inRetry,
      SqlDataReader ds, Boolean describeParameterEncryptionRequest)    at
      System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
      cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
      method, TaskCompletionSource<code>1 completion, Int32 timeout, Task&amp; task,
      Boolean&amp; usedCache, Boolean asyncWrite, Boolean inRetry)    at
      System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
      cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
      method)    at
      System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
      behavior, String method)    at
      System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
      behavior)    at
      System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)<br>
      at
      System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.&lt;Reader&gt;b__c(DbCommand
      t, DbCommandInterceptionContext</code>1 c)    at
      System.Data.Entity.Infrastructure.Interception.InternalDispatcher<code>1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget
      target, Func</code>3 operation, TInterceptionContext interceptionContext,
      Action<code>3 executing, Action</code>3 executed)    at
      System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand
      command, DbCommandInterceptionContext interceptionContext)    at
      System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior
      behavior)    at
      System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)<br>
      at
      System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary<code>2
      identifierValues, List</code>1 generatedValues)    at
      System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
      --- End of inner exception stack trace ---    at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
      at
      System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.b__2(UpdateTranslator
      ut)    at
      System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T
      noChangesResult, Func<code>2 updateFunction)    at
      System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()<br>
      at
      System.Data.Entity.Core.Objects.ObjectContext.&lt;SaveChangesToStore&gt;b__35()
      at
      System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func</code>1
      func, IDbExecutionStrategy executionStrategy, Boolean
      startLocalTransaction, Boolean releaseConnectionOnSuccess)    at
      System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions
      options, IDbExecutionStrategy executionStrategy, Boolean
      startLocalTransaction)    at
      System.Data.Entity.Core.Objects.ObjectContext.&lt;>c__DisplayClass2a.b__27()
      at
      System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func<code>1
      operation)    at
      System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions
      options, Boolean executeInExistingTransaction)    at
      System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions
      options)    at
      System.Data.Entity.Internal.InternalContext.SaveChanges()    --- End
      of inner exception stack trace ---    at
      System.Data.Entity.Internal.InternalContext.SaveChanges()    at
      System.Data.Entity.Internal.LazyInternalContext.SaveChanges()    at
      System.Data.Entity.DbContext.SaveChanges()    at
      System.Data.Entity.Migrations.DbMigrator.SeedDatabase()    at
      System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
      at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable</code>1
      pendingMigrations, String targetMigrationId, String lastMigrationId)<br>
      at
      System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1
      pendingMigrations, String targetMigrationId, String lastMigrationId)<br>
      at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String
      targetMigration)    at
      System.Data.Entity.Migrations.DbMigrator.&lt;>c__DisplayClasse.b__d()
      at
      System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action
      mustSucceedToKeepDatabase)    at
      System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action
      mustSucceedToKeepDatabase)    at
      System.Data.Entity.Migrations.DbMigrator.Update(String
      targetMigration)    at
      System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String
      targetMigration)    at
      System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
      at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()</p>
    </blockquote>
  </blockquote>