This post was last edited by QWERTYU on 2020-7-3 14:43
Prerequisites:
Steps: 1: AddADO.NET Entity Data Model, select CodeFirst Model.
2: AddMySql.Data.Entity (note that the version should be the same as the one installed in the machine).
3: Add modify the connection string, (If it is a newly created class library, you should manually add the connection string in the application configuration file. )
4: Add a test user class.
5: OpenNuGet package management console and select the corresponding project. Execute enable-migrationscommand, which generates a folder with the version numberMigrations
6: In the generated Migrations folder, add SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
7: Executionadd-migrationcommand, enter the name of a version number. (This step is required every time the model is modified in the future.)
8: Executionupdate-databasecommand(Update-Database -Verbose Add one-Verboses to view the generated SQL statements)After executing this command, the database will be generated (this step will be required every time the model is modified in the future).
Error Problem Resolution: 1: Execute Enable-Migrations, error is reported:The type of member "System.Data.Entity.Migrations.Design.ToolingFacade+GetContextTypeRunner,EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" is not resolved. Solution: Look at the class libraries and applications usedWhether the EntityFramework version is consistent, my library is 6.2.0, the application is 6.1.3, change the application to 6.2.0, and the error is not reported when executed again.
2: ExecutionAdd-Migration, error:No MigrationSqlGenerator was found for the provider "MySql.Data.MySqlClient". Use the SetSqlGenerator method in the target migration configuration class to register additional SQL generators. Solution:Add in the constructorSetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
|