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