I am developing a web application and of course on each phase I need to change the database schema on test server. When I tried to publish my code to my azure app service, it showed me an error:
Error : .Net SqlClient Data Provider: Msg 50000, Level 16, State 127, Line 6 Rows were detected. The schema update is terminating because data loss might occur
I understand, it wants to delete some columns and of course some columns should be deleted. My question is, how can I tell it to Drop the columns anyway?!
I've removed all rows from affecting tables and the publishing went through. But there should be a way that I can keep my data and just drop that column.
besides, what is the solution on production?
I have found this post in msdn mentioning that: you can uncheck the "Block the update if data loss might occur" option under Data | Schema Compare | Schema compare options.
But I guess that is only there if you have a database project. how to do it on code first?
Look at adding a deployment script to your project. This allows you to do things with T-SQL that are blocked for data integrity reasons on a publish. I'm not positive if this is available for the specific type of project you are doing, but I've used them in the past to do a blocked schema changes on a database project.