EF报错:Unable to create an object of type 'XXXXXXX'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

这个是在EF迁移的时候报错:

 解决方案:
修改你的MyDbcontext:

 

 代码如下:

public class StoreDbContexttFactory : IDesignTimeDbContextFactory< ‘你的类名’>
{
public ‘你的类名’CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder< ‘你的类名’>();
optionsBuilder.UseSqlServer("server=.;uid=sa;pwd=123456;database=Ceshi123123");

return new  ‘你的类名’(optionsBuilder.Options);
}
}

然后再次迁移:

 ok成功!

posted @ 2023-11-10 11:12  S提拉米苏  阅读(547)  评论(0编辑  收藏  举报