ASP.NET Core Code first, database initilization

asp.net-core ef-code-first ef-migrations entity-framework-core

Question

I have this ASP.NET Core project.

enter image description here

and the connection string that points to my SQL database.

 "ConnectionStrings": {
    "DefaultConnection": "Data Source=localhost;Initial Catalog=RestaurantDatabase;Integrated Security=True;Trusted_Connection=True;MultipleActiveResultSets=true"}

I need to initialize the database, thus run migration script. I've tried with update-database but that did not work. What is the first step when initializing database from code?

UPDATE:

PM> dotnet ef migrations add InitialCreate
dotnet : No executable found matching command "dotnet-ef"
At line:1 char:1
+ dotnet ef migrations add InitialCreate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

PM> Install-Package Microsoft.EntityFrameworkCore.Tools
  CACHE https://api.nuget.org/v3/registration3-gz-semver2/microsoft.entityframeworkcore.tools/index.json
Restoring packages for E:\xxxx\Restaurant-App\src\Server\Restaurant.Server.Api\Restaurant.Server.Api.csproj...
Install-Package : NU1605: Detected package downgrade: Microsoft.EntityFrameworkCore.Design from 2.0.2 to 2.0.1. Reference the package directly from the project to select a 
different version. 
 Restaurant.Server.Api -> Microsoft.EntityFrameworkCore.Tools 2.0.2 -> Microsoft.EntityFrameworkCore.Design (>= 2.0.2) 
 Restaurant.Server.Api -> Microsoft.EntityFrameworkCore.Design (>= 2.0.1)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Tools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Install-Package : Package restore failed. Rolling back package changes for 'Restaurant.Server.Api'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Tools
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand


PM> Add-Migration myMigration
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\xxxx\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
infoinfo: IdentityServer4.Startup[0]
      You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
: IdentityServer4.Startup[0]
      You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
dbug: IdentityServer4.Startup[0]
      Using Bearer as default scheme for authentication

Nuget packages Nuget packages

The script in question is this -> https://github.com/Jurabek/Restaurant-App

1
1
11/21/2018 3:16:06 AM

Popular Answer

NOTE: the Restaurant.Server.Api.csproj configured by DotNet command line not with Package Manager and also you don't need to create the initial migration.

you need to go to the src\Server\Restaurant.Server.Api>

run that commands with command line dotnet restore

and dotnet ef-database update

1
4/17/2018 12:47:34 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow