EF Code-First (Oracle) updates the fields of the database table through Migration,

Source: Internet
Author: User

EF Code-First (Oracle) updates the fields of the database table through Migration,

For details about how to use Entity Framework 6.x Code-First in Oracle, refer to blog (Yang Guo under the bodhi tree) coding Framework for Code-First development and Database Migration creation are explained in detail and the official reference links. I will not go into details here.

When you use CodeFirst of EntityframeWork to write a program, you will often encounter the need to modify the object content (that is, the content of fields in the Table). In this case, you need to use Database Migration, however, some problems are inevitable in the actual process. Here we will record several problems I encountered and solutions.

1. For more information about how to create and use Migration, see the connection references in this article. Here we will summarize several usage commands.

Tools> Package Manager Console, 1) Enable-Migrations; 2) Add-Migration MigrationName; 3) update-Migration.

2. An error occurred while updating-Migration.

Update-Migration sometimes has errors. There are many causes of errors, which may be due to configuration problems, database causes, and other causes. If the solution cannot be found at this time, at this time, it is helpless to regenerate the fields of tables or tables corresponding to object attributes. For example, in actual development, if I add [MaxLength] Attribute to a string type Attribute without [Attribute], the Migration will be generated, but the Update-Migration will not be used. Instead, you have to delete the old property before adding it. You can.

3. An error occurred while adding-Migration.

Add-Migration errors generally result in "Unable to generate an explicit migration because the following explicit migrations are pending: [MigrationName]. apply the pending explicit migrations before attenpting to generate a new explicit migration ". This error occurs because the previous Migration Command (New Add-Migration Command) is not executed (Update-Migration) and is in pending state, you only need to run the command to execute the migration and then the pending state is removed. Generally, update-migration cannot be executed, and the subsequent add-migration cannot be continued. Here, we can first comment out the code in the "public override void up ()" method in the previous Migration to execute the Update-Migration command, so that there will be no actual operations on the database, the pending status is also removed. Then you can add a new Migration.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.