title: Entity Framework migrations changes detection
body: <p>I've been recently digging into how EF migrations work and I've encountered an issue I could not really understand. </p>
  
  <p>I was reading <a href="https://msdn.microsoft.com/en-us/data/dn481501.aspx" rel="nofollow noreferrer">this</a> article and here's what I saw:</p>
  
  <p><a href="https://i.stack.imgur.com/9cCe8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9cCe8.png" alt="screen from msdn"></a></p>
  
  <blockquote>
    <p>At this stage Developer #2 can run Update-Database which will detect
    the new AddRating migration (which hasn’t been applied to Developer
    2’s database) and apply it. Now the Rating column is added to the Blogs table and the database is in sync with the model.</p>
  </blockquote>
  
  <p>What I can't get is how EF determines that it has to apply the changes from the AddRatings migration. As far as I know, the workflow is as follows:</p>
  
  <ol>
  <li>Suppose we have two migrations (with the ids 4 and 5) in the project which have not been applied to the db (say, we got the old version of the db with 1, 2 and 3 migrations applied).</li>
  <li>Update Db command is run.</li>
  <li>EF goes to the db, looks up the MigrationHistory table and gets the latest migration. Then, EF sees that there are migrations 4 and 5 in the project and since the latest migration in the db is 3, it applies 4 and 5. </li>
  </ol>
  
  <p>However, when I look at the screen from the article, I don't really get it. Here's how I would expect it to go:</p>
  
  <ol>
  <li>There are migrations First, AddUrl and AddReaders in the Dev 2 database. </li>
  <li>EF looks up the latest migration in the db - it's the AddReaders.</li>
  <li>The latest migration in the project is also AddReaders. </li>
  <li>Therefore, no changes have to be applied at all. </li>
  </ol>
  
  <p>There's an issue that the code model and the latest migration model are not the same, but EF is able to apply changes to the db anyway, though producing a warning, as the article says.</p>
  
  <p>The question is, what have I got wrong in my reasoning and how EF understands that even though the latest migration in the db and code <strong>is the same</strong>, there's another migration that has to be applied.</p>
  
  <p>Also, as far as I've understood, the compressed model in the MigrationHistory serves <strong>only</strong> when the Add-Migration command is run and has nothing to do with the Update-Database command. Is it so?</p>