Errors on Data migration - asp.net

Add-Migration InitialCreate
While running this command , an error is coming while creating an API in ASP .NET
Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At line:1 char:1
Add-Migration InitialCreate
+ CategoryInfo : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I do not have Migration folder as well as migration table in my database.

View -> Other windows -> Package Manager Console then run
install-package Microsoft.EntityFrameworkCore.Tools
Now run your command Add-Migration and your good to go.

Related

firebase.ps1 cannot be loaded because running scripts is disabled on this system

firebase sends this error if I try firebase init. can anyone please help me with this. I am new. and I don't really know much.
firebase : File C:\Users\USER\AppData\Roaming\npm\firebase.ps1 cannot be loaded because running scripts is disabled on
this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
firebase init
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Step 1 :
open Windows PowerShell (Run as administrator)
Step 2 :
Type in Get-ExecutionPolicy -List and hit Enter.
Step 3 :
Type in Set-ExecutionPolicy Unrestricted and hit Enter again.
Step 4 :
Type Y and hit Enter.
Step 5 :
Type Set-ExecutionPolicy Unrestricted -Force and hit Enter.

add-migration : Cannot bind argument to parameter 'Path' because it is null

I want to enable migration in visual studio 2017. When I run it, I'm getting an error. The error message is:
add-migration : Cannot bind argument to parameter 'Path' because it is
null. At line:1 char:1
+ add-migration ApplyAnnotationsToCustomerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Migration], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-Migration.
I tried to uninstalling and reinstall EntityFramework and it didn't work.
Also my startup project is set to the project with EF.
nothing worked!!
Ohh... spent hours trying to figure this one out. I tried all the suggestions I could find and even tried what you did uninstalling and reinstalling EF. Nothing seemed to work and it was really frustrating. In the end what ultimately worked for me was how I uninstalled and reinstalled EF!
Uninstall:
PM> Uninstall-Package EntityFramework -Force
Reinstall EntityFramework:
PM> Install-Package EntityFramework -Pre
Source: https://entityframework.net/knowledge-base/14410987/entity-framework-code-first-migration-error

EntityFramework Core database first, Scaffold-DbContext A positional parameter cannot be found that accepts argument '--use-database-names' error

I am trying to create the model from existing DB using EntityFramework Core, database first approach. The model was created, but the table name and column name were changed to C# style. Because I want the model still using exact table name and column name as in the database, so I append the "--use-database-names" in the command line, according to Entity Framework Core tools reference
Following is the command executed in the Package Manager Console:
Scaffold-DbContext "Server=aServer;Database=someDb;Trusted_Connection=True" Microsoft.EntityFrameworkCore.SqlServer -o Models --use-database-names
But I got following error:
Scaffold-DbContext : A positional parameter cannot be found that accepts argument '--use-database-names'.
At line:1 char:1
Scaffold-DbContext "Server=aServer;Database=someDb;Trusted_Conn ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidArgument: (:) [Scaffold-DbContext], ParameterBindingException
FullyQualifiedErrorId : PositionalParameterNotFound,Scaffold-DbContext
Has anybody encounter this issue? Did I miss something? Thanks in advance!
Following are some basic info of the simple project.
IDE: Visual Studio 2017
Target framework: .NET Core 2.1
Installed NuGet Package:
Microsoft.EntityFrameworkCore.Design(2.2.0)
Microsoft.EntityFrameworkCore.SqlServer(2.2.0)
Microsoft.EntityFrameworkCore.Tools(2.2.0)
Microsoft.EntityFrameworkCore.SqlServer.Design(1.1.6)
Like in the reference for Package Manager Console mentioned, you have to write:
-UseDatabaseNames
not
—use-database-names

CommandNotFoundException in asp.net mvc 5 database migration

I tried to run this command:
Enable-Migrations -ContextType ApplicationDbContext
And getting this exception:
Enable-Migrations : The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enable-Migrations -ContextType ApplicationDbContext
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I am using vs 2015 community edition. Restarting and run it as administrator could not solve the issue. And if I try to run this command to reinstall Entity Framework:
Install-Package EntityFramework -IncludePrerelease
Getting this exception as well:
Install-Package : An error occurred while retrieving package metadata for 'Newtonsoft.Json.10.0.3' from source 'C:\Path\packages'.
At line:1 char:1
+ Install-Package EntityFramework -IncludePrerelease
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Please, Give me any solution.
its case sensitive type
enable-migrations -contexttypename DBCONTEXT
you can also see the available options from
get-help EntityFramework

NuGet execution policy errors when installing MvcScaffolding package

I'm using Visual Web Developer Express 2010, Windows XP, and using ASP.NET MVC4 RC in a project. I have NuGet v2.0.30619.9119 installed.
I'm now trying to install the MvcScaffolding package via NuGet Package Manager Console. I get the following errors:
PM> Install-Package MvcScaffolding
Attempting to resolve dependency 'T4Scaffolding'.
Attempting to resolve dependency 'EntityFramework (≥ 4.1.10311.0)'.
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=224682. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 4.1.10715.0'.
Successfully installed 'T4Scaffolding 1.0.6'.
File Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps1 cannot be loaded. The file Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps
1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<< 'Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps1' $__rootPath $__toolsPath $__package $__project
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Successfully installed 'MvcScaffolding 1.0.7'.
File Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.ps1 cannot be loaded. The file Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.
ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<< 'Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.ps1' $__rootPath $__toolsPath $__package $__project
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Successfully added 'EntityFramework 4.1.10715.0' to MyProject.Web.
Successfully added 'T4Scaffolding 1.0.6' to MyProject.Web.
File Y:\asp\packages\T4Scaffolding.1.0.6\tools\install.ps1 cannot be loaded. The file Y:\asp\packages\T4Scaffolding.1.0.6\tools\inst
all.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<< 'Y:\asp\packages\T4Scaffolding.1.0.6\tools\install.ps1' $__rootPath $__toolsPath $__package $__project
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
'InstallationDummyFile.txt' already exists. Skipping...
Successfully added 'MvcScaffolding 1.0.7' to MyProject.Web.
File Y:\asp\packages\MvcScaffolding.1.0.7\tools\install.ps1 cannot be loaded. The file Y:\asp\packages\MvcScaffolding.1.0.7\tools\in
stall.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<< 'Y:\asp\packages\MvcScaffolding.1.0.7\tools\install.ps1' $__rootPath $__toolsPath $__package $__project
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Because the init scripts aren't being executed after the install, the MvcScaffolding package is not installed correctly and the scaffold command is not recognised.
I don't know what to do about these code signing issues. Here are the current security settings:
PM> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process RemoteSigned
CurrentUser Undefined
LocalMachine Unrestricted
Can I change the Process scope to be Unrestricted? If so, how? Running Set-ExecutionPolicy in the NuGet console does not work:
PM> Set-ExecutionPolicy Unrestricted
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):Y
Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will
retain its current effective execution policy of "RemoteSigned". Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information, please see "Get-Help Set-ExecutionPol
icy."
At line:1 char:20
+ Set-ExecutionPolicy <<<< Unrestricted
+ CategoryInfo : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
+ FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
I've also tried doing all of this as an Administrator and that didn't help either.
Any advice or ideas would be much appreciated.
UPDATE
I can set the process execution policy in NuGet like this:
Set-ExecutionPolicy Unrestricted -Scope Process
But when I restart Visual Web Developer, the setting is forgotten and I still get an error as it keeps trying to execute the init.psl files
How can I change the execution policy permanently?
OK, I have MvcScaffolding installed correctly now.
I had to first bypass all security in NuGet:
Set-ExecutionPolicy Bypass -Scope Process
But when I restart Visual Web Developer I still get those same PowerShell errors todo with the NuGet running init.pls on startup.
I've worked out that it's because I was storing my project on a network drive. Apparently PowerShell won't execute scripts from the network drive by default.
I tried using CasPol to change the security settings, but couldn't get it to work. I gave up when I saw other people couldn't get VS to work with mapped drives as well:
CAS not working for VS2010 mapped drive
Anyway, I just have my project local now, and MvcScaffolding is installed and working.
You can set the policy for user scope and using a more secure policy like this:
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser
Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
Prompts you before running scripts from publishers that you have not yet classified as trusted or untrusted.
For exemple, installing a EntityFramework ask permission to run the script:
Executing script file 'c:\users\user\documents\visual studio 2015\Projects\zzz\packages\EntityFramework.6.1.3\tools\install.ps1'
Do you want to run software from this untrusted publisher?
File C:\users\user\documents\visual studio 2015\Projects\zzz\packages\EntityFramework.6.1.3\tools\install.ps1 is published by CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D"):R

Resources