- Brief introduction
- The project uses MSSQL as a database, but because the SQL Server is a bit more expensive and the concurrency connection is a little bit worse, migrating data to MySQL, incidentally, and the problem.
- Environment
- Visual Studio 2013
- MySQL 5.7
- Entity Framework 6.1.3
- Body
- Migration process
- Install MySQL, incidentally install MySQL for Visual Studio, MySQL Connector Net
- Add a NuGet package to the Entity Framework Project and the website project. MySql.Data.Entity, I added here is the 6.9.6 version, add the Mysql.data as a dependency after adding to the project, you can see that after completing the Web. config and app. Config added MySQL Provider and Dbprovidefactories.
- Modify the connection string for Web. config, providername modified to: MySql.Data.MySqlClient.
- Back in the EntityFramework project, locate the DbContext class and add properties for the class: [Dbconfigurationtype (typeof (MySql.Data.Entity.MySqlEFConfiguration))]
- OK, these jobs are done, basically, open the Package Manager console, pray, and then enter: Update-database
- Migration issues
- Object references are not set to an instance of an object.
- Problem Description: This is a more general error hint, many errors will prompt this, the Internet to find some less right, the final discovery is because the startup item is set to the EF project, and the default project is also the EF project, because the config file is not caused by the connection string.
- Solution: Add a connection string to the Ef App. Config, or the startup project is set to website.
- Underlying provider does not support the type ' nvarchar (max) '.
- Problem Description: Literally means that provider does not support type "nvarchar (max)", which is related to the data types supported by the MySQL database.
- Solution: Find out if the entity definition has a String type, add properties such as: [Stringlength (1000)], and then solve the problem.
EF6 Codefirst+mysql Database Migration