zoukankan      html  css  js  c++  java
  • Asp.net Core 添加 EF 工具并执行初始迁移错误解决方法(Add-Migration Initial---Build failed.)

    1.
    问题:

    首次在ASP.NET Core项目中使用Code First模式的Entity Framework框架,在添加EF工具并做初始化迁移(perform initial migration),执行Add-Migration Initial遇到以下错误:

    PM> Add-Migration Initial
    Add-Migration : 无法将“Add-Migration”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
    所在位置 行:1 字符: 1
    + Add-Migration Initial
    + ~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    网上关于此问题,有其他环境下的解决方案,其思路具有参考意义,但环境不同解决细节也不同。

    参考链接如下: 

    http://www.cnblogs.com/pari-Zhong/p/5339028.html

    在本人这个环境下,对PowerShell的ExecutionPolicy也是执行了设置了的。之后的细节如下:

    1、 编译项目。首次在项目中添加EF Core后,这一步必须做,否则都找不到后续要导入的 EntityFrameworkCore.psd1 模块。

    2、找到前述文件的位置,使用Import-Module命令导入。我这里为: Import-Module C:Users{用户名}.nugetpackagesmicrosoft.entityframeworkcore.tools1.1.1 oolsEntityFrameworkCore.psd1

    执行信息如下:

    PM> Import-Module C:Users*.nugetpackagesmicrosoft.entityframeworkcore.tools1.1.1 oolsEntityFrameworkCore.psd1

    模块“EntityFrameworkCore”中的某些导入命令的名称包含未批准的动词,这些动词可能导致这些命令名不易被发现。若要查找具有未批准的动词的命令,请使用 Verbose 参数再次运行 Import-Module 命令。有关批准的动词列表,请键入 Get-Verb。

    之后问题解决,执行Add-Migration Initial  ,Update-Database这些命令都正常了。

    2.如果执行1操作后还是Build failed,就看看是否Visual Studio中Build failed,因为我这里没有用到docker,所以我这里卸载项目就正常了

  • 相关阅读:
    Codeforces Round #380(div 2)
    Codeforces Round #378(div 2)
    Codeforces Round #379(div 2)
    CCPC2016合肥现场赛
    CCPC2016沈阳站
    HDU2222 Keywords Search__AC自动机
    poj2185Milking Grid
    POJ2961_kmp
    POJ 2406
    poj 2752Seek the Name, Seek the Fame
  • 原文地址:https://www.cnblogs.com/lbonet/p/9143686.html
Copyright © 2011-2022 走看看