Rows were detected. The schema update is terminating because data loss might occur
If you have seen this error either in your release pipeline when you are deploying a dacpac file to SQL Server or during your build, then the reason you are seeing this error is because:
- The schema that you are trying to deploy does not match the schema that is already existing on the server.
- Due to this, there will be data loss and the missing columns will be dropped from the server.
Usually, this is not something that you want to do if you are deploying to production.
Hence, when the following flag is set to true, it will block such dangerous deployment and your deployment will fail. The name of this flag is: BlockOnPossibleDataLoss
Here is how you fix it depending on how you want to solve this problem:
Preserve data on production server and prevent data loss
- Check your release pipeline / logs to see which tables and columns are impacted where data loss can occur.
- Add those tables / columns to the schema you are trying to deploy.
- This will ensure that no data is lost when you deploy and ensure a successful deployment.
Force Deploy to SQL Server (Can cause data loss)
- Check your release pipeline for the following parameter / flag being passed: BlockOnPossibleDataLoss
- Set the flag to false.
- Re-trigger the release.
- This will ensure that you force deploy the new schema on SQL server and the tables and columns that are not part of the schema get dropped.