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?
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://learn.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://learn.microsoft.com/en-us/powershell/scripting/install/windows-powershell-system-requirements?view=powershell-7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With