When executing the command “Scaffold-DbContext” I get the error “ScriptHalted”

◇◆丶佛笑我妖孽 提交于 2020-02-25 05:42:27

问题


I am trying to compute the entity framework tutorial" Creating a Model for an Existing Database in Entity Framework Core // entityframeworktutorial.net"-  

When I enter the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models  
I get the error: ScriptHalted  

Database Picture

Used by:
   - Visual Studio - 2019. Community - 16.3.6;
   - Console application. Core 3.0;
   - Microsoft.EntityFrameworkCore - 3.0.0;
   - Microsoft.EntityFrameworkCore.Tools - 3.0.0;
  Story:
  - I installed "Microsoft.EntityFrameworkCore - 3.0.0;"
  - I run the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

  - I get an error: The name" Scaffold-DbContext "is not recognized as the name of the cmdlet, function, script file, or executable program. Check for correctness. spelling of the name, as well as the presence and correctness of the path, then try again. line: 1 character: 19 + Scaffold-DbContext <<<< "Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True;" Microsoft.EntityFrameworkCore.SqlSe rver -OutputDir Models     + CategoryInfo: ObjectNotFound: (Scaffold-DbContext: String) [], CommandNotFoundException     + FullyQualifiedErrorId: CommandNotFoundException

  - I installed Microsoft.EntityFrameworkCore.Tools (according to the recommendation -"Scaffold-DbContext 'is not recognized -> require EF Tools // github.com")`

  - I run the command: PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
  - I get an error: ScriptHalted
  Question.
How to fix the "ScriptHalted" error?


回答1:


I had the same problem today and I am using Windows 7. Windows 7 uses powershell 2.0 so I upgraded it to 5.1, you can upgrade it from here - https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6

Upgrading this solved my problem. I found this solution from here - https://github.com/aspnet/AspNetCore.Docs/issues/14863




回答2:


Upgrade Powershell to 5.1

This is the link from where you can download according to your system requirement.

https://docs.microsoft.com/en-us/powershell/scripting/install/windows-powershell-system-requirements?view=powershell-7



来源:https://stackoverflow.com/questions/58607253/when-executing-the-command-scaffold-dbcontext-i-get-the-error-scripthalted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!