简体   繁体   中英

Errors on Add-Migration

A few weeks ago I enabled migration on my project and added a column 'ClientID' to the AspNetUsers table.

PM> Add-Migration "Name"
  1. Remove the Migrations folder in your project

  2. Delete the _MigrationHistory table from your database.

  3. Run the Enable-Migrations command from your Package Manager Console.
  4. Run the Add-Migration Init command to create a migration.
  5. Remove all of the code lines in Up() function for the initial migration. (To create an empty migration and solve the errors that you are facing.)
  6. Run the Update-Database command to apply your empty migration.
  7. Make changes to your code first model for preparing to adding your real migration.
  8. Run the Add-Migration InitNew command to create a new migration.
  9. Run the Update-Database command to apply the changes.

Firstly try these plz: 1- clean the project up-root solution 2- close the visual studio 3- reopen vs and open the solution 4- build it. 5- totally remove the migrations folder under the entities folder 6- remove the table _projectnameMigrations from the DB 7- open the PMC in Vs 8- Enable-Migrations 9- Add-Migrations mig_Myinit 10- (!Important) clear the up method and make it empty 11- update-database 12- done Your next migrations... point is that if you remove a table manually from the database ef is not able to recognize it and by default it is accessible so when ur using ef you have to do any database-related tasks from the pmc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM