当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;
保证执行可以完成,大不了等一等,在这种需求之下可能并没有其他更好的办法。。。。