I ran into the following error after adding model validation attributes to a database with existing values:
String or binary data would be truncated.
The statement has been terminated.
The solution is pretty straightforward if you’re happy to truncate the values. Simply run the query below, swapping Title for your column name, Products for your table name and 25 for your new column length:
UPDATE Products SET Title = LEFT(Title, 25) WHERE LEN(Title) > 25
You should then be able to run update-database without any issues:
Specify the ‘-Verbose’ flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201806240741543_product_validation].
Applying explicit migration: 201806240741543_product_validation.
Running Seed method.
Thanks to David in for his answer on Stackoverflow: https://stackoverflow.com/a/24931522/522859