Note that there are some explanatory texts on larger screens.

plurals
  1. POChange migration file manually and and keep compatible __migrationhistory record
    primarykey
    data
    text
    <p>My team and I are having a lot o problems trying to keep our development (and, soon, the client's production) database in sync with our model while using Entity Framework Code First Migrations.</p> <p>It seems the problems started to happend when I had to manually edit a migration code because of a faulty DropForeignKey() method call. (My project is using MySQL 5.5, MySQL Connector 6.6.2, EF 4.3.) The problematic command:</p> <pre><code>DropForeignKey("Recebimento", "ComponenteFabricante_Id", "CompFab"); </code></pre> <p>was changed to:</p> <pre><code>DropForeignKey("Recebimento", "FK_RecebimentoMaterial_CompFab_ComponenteFabricante_Id"); </code></pre> <p>Since then, every time I try to <code>Update-Databse</code>, <strong>even when I know that I already have all migration code that reflect the current model mappings</strong>, the following message is displayed: "Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration. You can use the Add-Migration command to write the pending model changes to a code-based migration."</p> <p>I don't want to use change <code>AutomaticMigrationEnabled</code> to <code>true</code>, so I run <code>Add-Migration Test</code> to see what is been created. The file created contains commands that were already applied (by previous migrations) to the database. If I try and run this last migration, <code>Update-Database</code> fails (something like "Column already exists" or "Table already exists", which are the correct error messages since the migration has duplicated code).</p> <p>I suspect the problem has something to do with the values the table <code>__migrationhistory</code> saves on the Model column (a binary representation of the model applied by the migration) - maybe the value is not the correct value since a manual correction was made.</p> <p>What can I do to be able to manually edit migration code and have it work properly? What are the best practice when using Entity Framework Code First migrations?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload