當EF需要執行遷移的時候,
尤其是本次遷移涉及較為嚴重的資料結構變更
比如:
為之前的字段添加索引
添加遺漏的字段(盡量為非空,萬非得以是非空的時候)
等,
那極有可能遇到錯誤:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
------------------------------
System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
此時,即便使用migrate.exe去手動執行并且/force,依舊可能失敗。
需要修改的是,
Migrations目錄的Configuration.cs裡的構造器中添加:
CommandTimeout = int.MaxValue;
保證執行可以完成,大不了等一等,在這種需求之下可能并沒有其他更好的辦法。。。。