简体   繁体   English

运行更新数据库实体框架时出错2

[英]Error running update-database entityframeworkcore 2

I have EntityFrameworkCore 2.0.2 installed in a class library on a solution containing an AspNet Core WebApi. 我在包含AspNet Core WebApi的解决方案的类库中安装了EntityFrameworkCore 2.0.2

I have the following packages installed in the project; 我在项目中安装了以下软件包;

Microsoft.AspNetCore.Identity.EntityFrameworkCore - 2.0.2 Microsoft.AspNetCore.Identity.EntityFrameworkCore-2.0.2

Microsoft.EntityFrameworkCore - 2.0.2 Microsoft.EntityFrameworkCore-2.0.2

Microsoft.EntityFrameworkCore.SqlServer - 2.0.2 Microsoft.EntityFrameworkCore.SqlServer-2.0.2

Microsoft.Extensions.Identity.Stores - 2.0.2 Microsoft.Extensions.Identity.Stores-2.0.2

System.Data.SqlClient - 4.4.3 System.Data.SqlClient-4.4.3

My Class library project invokes the context as follows; 我的Class库项目按如下方式调用上下文;

 public class MyContextFactory : IDesignTimeDbContextFactory<MyDataContext>
    {
        public MyContextFactory()
        {
        }

        public MyDataContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MyDataContext>();
            builder.UseSqlServer(DbGlobals.DevDatabase);

            return new MyDataContext(builder.Options);
        }
    }

I am getting the following error, when I try to run the update-database command from the package manager console. 当我尝试从程序包管理器控制台运行update-database命令时,出现以下错误。

Application startup exception: System.IO.FileNotFoundException: Could not find file 'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'. 应用程序启动异常:System.IO.FileNotFoundException:找不到文件'C:\\ Users \\ matt \\ Source \\ Repos \\ project \\ Services.WebApi \\ bin \\ Debug \\ netcoreapp2.0 \\ ef.xml'。

this now occurs when I try to add-migration as well. 现在,当我尝试add-migration时也会发生这种情况。

I can't find any detail on ef.xml and how it is generated? 我找不到关于ef.xml及其生成方式的任何细节? Can anyone tell me what is going on here. 谁能告诉我这是怎么回事。

If I run an add-migration i get the migration generated, but then get the error; 如果我运行add-migration我会生成迁移,但是会收到错误;

An error occurred while calling method 'BuildWebHost' on class 'Program'. 在类“程序”上调用方法“ BuildWebHost”时发生错误。 Continuing without the application service provider. 没有应用程序服务提供商就继续进行。 Error: Could not find file 'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'. 错误:找不到文件'C:\\Users\\matt\\Source\\Repos\\project\\Services.WebApi\\bin\\Debug\\netcoreapp2.0\\ef.xml'.

I have tried cleaning the project, re-compiling (there are no errors), I have also looked in the referenced folder and the file doesn't exist. 我尝试清理项目,重新编译(没有错误),我还查看了引用的文件夹,并且该文件不存在。 Nor (from a file search) has it been generated elsewhere? 也没有(通过文件搜索)是否在其他地方生成?

The migrations have been working fine now? 迁移现在工作正常了吗?

Per request my BuildwebHost is; 根据请求,我的BuildwebHost是;

 public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();

and I add EF in my Startup.cs; 然后在Startup.cs中添加EF;

        services.AddDbContext<MyDataContext>(
            options => options
            .UseSqlServer(DbGlobals.DevDatabase));

The commands you are using update-database and add-migration don´t look like the supported Entity Framework Core CLI commands: 您正在使用的update-databaseadd-migration命令看起来不像受支持的Entity Framework Core CLI命令:

  • dotnet ef add migrations <migration-name>
  • dotnet ef database update

Also check this SO question for further information: Entity Framework Core 2.0 add-migration not generating anything 还要检查此SO问题以获取更多信息: Entity Framework Core 2.0 add-migration不生成任何内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在MVC5中运行Update-Database时出错 - Error while running Update-Database in MVC5 运行代码第一次迁移update-database时出错 - Error running code first migration update-database 运行更新数据库 EFCore 时出现算术溢出错误 - Arithmetic Overflow Error When running Update-Database EFCore 实体框架6中“更新数据库”之后发生错误 - Error after 'update-database' in Entity Framework 6 为MySql数据库运行更新数据库时出错:表&#39;xxx&#39;不存在 - Getting error when running update-database for MySql database: Table 'xxx' doesn't exist 尝试首先更新数据库代码时出错 - Error on trying to Update-Database code first DbContext继承更新 - 数据库错误 - DbContext inheritance update-database error 使用Entity Framework,Code First(POCO)和Code Contracts运行Update-Database时出错 - Error When running Update-Database using Entity Framework, Code First (POCO) and Code Contracts 实体框架-迁移更新数据库引发奇怪的错误 - Entity Framework - Migrations update-database Throwing strange error 使用更新数据库命令MVC 4时出错 - Error when using Update-Database command MVC 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM