[英]Add-Migration results in InvalidOperationException error. What is the correct command?
I was doing the tutorial from this website and stuck halfway. 我正在从该网站上进行教程,但仍中途停滞。
https://docs.microsoft.com/en-us/ef/core/get-started/uwp/getting-started
https://docs.microsoft.com/zh-cn/ef/core/get-started/uwp/getting-started
I was stuck at this line 我被困在这条线
Add-Migration MyFirstMigration
添加迁移MyFirstMigration
This are the errors that I get 这是我得到的错误
System.InvalidOperationException: No database provider has been configured for this DbContext.
System.InvalidOperationException:没有为此DbContext配置数据库提供程序。 A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider.
可以通过重写DbContext.OnConfiguring方法或在应用程序服务提供程序上使用AddDbContext来配置提供程序。 If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
如果使用AddDbContext,则还应确保DbContext类型在其构造函数中接受DbContextOptions对象,并将其传递给DbContext的基本构造函数。
It seems this error has been going on for some time but so far, Microsoft hasnt respond with a fix. 似乎该错误已经持续了一段时间,但到目前为止,Microsoft尚未提供修复程序。
What should I do? 我该怎么办?
ApplicationDbContext.cs ApplicationDbContext.cs
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=yorudbname.db");
}
//ONLY necessary if you needing to use Fluent API
protected override void OnModelCreating(ModelBuilder mb)
{
base.OnModelCreating(mb); //required reference comment - Order Matters as well.
//ie has to be at the top.
now you will need to 2 other piece data in your project.json 1) Design
2) Tools
listed below. 现在您需要在project.json中添加其他2个数据。json 1)
Design
2)下面列出的Tools
。
project.json project.json
"dependencies": {
"Microsoft.EntityFrameworkCore.Design": "1.1.1", <<required
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.1",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.3.1", << must be 5.2.2 or higher
"Microsoft.Xaml.Behaviors.Uwp.Managed": "2.0.0",
"MvvmLight": "5.3.0",
"Newtonsoft.Json": "10.0.2",
"Unity": "4.0.1"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.1" << required
don't pay any attention to the versions in this example get the latest version available . 不要注意本示例中的版本获取最新的版本 。
make sure all that is correctly placed and recompile, might even have to close project and reopen, commands should run then. 确保所有正确放置并重新编译,甚至可能不得不关闭项目并重新打开,然后应运行命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.