I' m working on a ASP.Net MVC project using Visual Studio 2017 .I want added a property to one of my models After i the migrations and starting the application i m getting and error message "There is already an object named in the database" . as i found on the internet this is occurred due to automatic migrations , how to change my migration command to avoid this .
dotnet ef migrations add GeoLocation -c ApplicationDb -o Data/Migrations/IdentityServer/ApplicationDb
I do use EF migrations but I'm still not a fan. I prefer to develop in both SQL Server and C# separately. You can work around issues in various ways
Open a Nu-Get Package manager console and enable migrations for your project
Enable-Migrations -ContextTypeName YourProject.Models.ApplicationDbContext -Force
You can migrate whatever you have in your migration folder as follows (I've just shown the initial one) with or without the ignore changes flag
add-migration Initial
Add-Migration Initial -IgnoreChanges
Finally, force through the changes
Update-Database -Force
I always copy the contents of the "Configuration" file because that can get overwritten when I don't want. It can also add duplicate data to the database if your are not careful when it runs on a migration - so you'll need to code around that.
If I'm really stuck, I simply delete all migrations, truncate the migrations table, then perform an initial migration again.