For the development of Oracle using the entity Framework 6.x Code-first, please refer to the blog (Yang over under the Bodhi tree) https://www.cnblogs.com/yjmyzz/p/ How-to-use-code-first-in-oracle-with-entity-framework-6.html specific introduction, inside about the use of entity The framework carries out Code-first development and the creation of database migration with detailed explanations and official reference connections. This is not to be discussed here.
When using EntityFramework's Codefirst to write programs, you will often encounter the need to modify the entity content (that is, the contents of the table field), this time need to use the database migration, but in the actual process will inevitably encounter some problems, Here are a few of the problems I have encountered, and how to solve them.
1, about the creation and use of migration, the link reference article in this article already has, here summarizes a few use commands.
Tools (Tools)--Package Manager--Package Manager Console (Pack Manager console), 1) enable-migrations ; 2) add-migration migrationname;3) update-migration.
2, update-migration error.
Update-migration sometimes error, the cause of the error is a lot of reasons, may be a configuration problem, may be a database cause, and other reasons, if the solution is not found at this time, this time to regenerate the entity corresponding table or entity properties corresponding to the table field, is an alternative to the helpless. For example, if I encounter a string type attribute added [Maxlength]attribute] that is not added [Attribute] in real development, the generation of migration will not update-migration. But I had to remove the old attributes and add them. You can do it.
3, add-migration error.
Add-migration error is generally easy to error is "unable to generate an explicit migration because the following explicit migrations is Pending:[mi Grationname]. Apply the pending explicit migrations before attenpting to generate a new explicit migration ". This error is due to the fact that a new (new add-migration Command) migration is not executed (update-migration), in the state of the orders (pending). If you run the command first, the migration executes and the pending state is lifted. Generally because the update-migration can not be executed to cause the latter add-migration cannot continue. The code in the "public override void Up ()" method inside the previous migration is used to annotate the execution of the update-migration command so that there is no actual operation on the database and the pending state is lifted. Then you can add a new migration.
EF Code-first (Oracle) updates the fields of a database's tables by migration