简体   繁体   中英

When executing the command "Scaffold-DbContext" I get the error "ScriptHalted"

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 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?

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

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

I have had the same error, everything was correct and there was no problem with the packages, nor problems with PowerShell. What happened was that I copied the script that I had done before from GitHub and pasted it into the Visual Studio package management console, without knowing that when I copied this from GitHub I copied a strange character that was invisible in the console, but which was causing the error.

Be careful when copying and pasting code or scripts because this can happen to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM