ABP. Net Core Entity framework migrations using MySQL database

Source: Internet
Author: User

I. Migration instructions

The ABP Template project entity Framework Core uses SQL Server by default, and it is easy to migrate the database to MySQL, as follows.

Ii. migrating MySQL Steps

1. Download the project

Go to Http://aspnetboilerplate.com/Templates to download a new project, select the ASP. NET Core 2.x tag, Target Framework: check.

2. Remove the default SQL Server related packages

Remove the package Microsoft.EntityFrameworkCore.SqlServerunder the Entityframeworkcore project, Microsoft.EntityFrameworkCore.Design

3. Add MySQL Package

Add Package Pomelo.EntityFrameworkCore.MySql,Pomelo.EntityFrameworkCore.MySql.Design

4. Modify the source code

Modify Dbcontextconfigurer

 Public Static classabpbasicdbcontextconfigurer{ Public Static voidConfigure (dbcontextoptionsbuilder<abpbasicdbcontext> Builder,stringconnectionString) {            //Builder. Usesqlserver (connectionString);Builder.        Usemysql (connectionString); }         Public Static voidConfigure (dbcontextoptionsbuilder<abpbasicdbcontext>Builder, DbConnection connection) {            //Builder. Usesqlserver (connection);Builder.        Usemysql (connection); }}

5. Modify the database link string

In the Web project configuration file Appsettings.json

"ConnectionStrings": {    //"Default": "Server=localhost; DATABASE=ABPBASICDB; trusted_connection=true; "    " Default ":" Server=localhost; port=3306; DATABASE=ABPBASICDB; Uid=root; pwd=****; Convert Zero Datetime=true "}

6. Data migration

Regenerate migration files

When you download the startup template, if you select Include Module Zero. There are some migration files that are included in your project, but these files are used for SQL Server migrations. Please open it. EntityFramework the Migrations folder in the project, and then delete the migrated files. The migration file starts with a timestamp. The name of the migrated file looks like this: 201506210746108_abpzero_initial.

After deleting all the migrated files, select your. The WEB project starts with the project, opens the VS package management console, and is selected in the Package management console. EntityFramework Project as the default project. Then execute the following command in the console:

Add-migration "Abpzero_initial"

Now you can use the following command to create the database:

Update-database

All the things are done, check that the MySQL database has been produced successfully

7. Run browse success after MySQL migration is completed

ABP. Net Core Entity framework migrations using MySQL database

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.