3

Visual Studio 2012 NuGet 패키지 관리자 콘솔을 사용하여 새 데이터베이스를 만들려고합니다. 내가 마이그레이션을 가능하게하기위한 모든 단계를 수행 한 은 마이그레이션 폴더가 성공적으로 만들어, 그 구성 클래스는 다음과 같이 정의 하였다 :MVC 4 - NuGet 패키지 관리자 콘솔을 사용하여 데이터베이스를 만들 수 없습니다.

internal sealed class Configuration : DbMigrationsConfiguration<MyMVC4Project.Infrastructure.CategoryDb> 
{ 
    public Configuration() 
    { 
     AutomaticMigrationsEnabled = true; 
    } 

    protected override void Seed(MyMVC4Project.Infrastructure.CategoryDb context) 
    { 
     context.Categories.AddOrUpdate(d => d.Name, 
      new Department() {Name = "dishes"}, 
      new Department() {Name = "Appliances"}, 
      new Department() {Name = "furniture"} 
      ); 
    } 
} 

PM> 업데이트를 데이터베이스 -Verbose

하는 점 I에서 오류 메시지가 표시 : 그럼 어떤 데이터베이스가 App_data 폴더에 만들어지지 않습니다

Using StartUp project 'MyMVC4Project'. 
Using NuGet project ' MyMVC4Project '. 
Specify the '-Verbose' flag to view the SQL statements being applied to the target database. 
Target database is: 'MyMVC4Project.Infrastructure.CategoryDb' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention). 
No pending code-based migrations. 
Running Seed method. 

을, 나는 localDb 데이터베이스를 찾을 것으로 예상하고 아닌 SQL Express를 한 후 설치 SQL Express 인스턴스가 "SQLExpress입니다"가 아닌 다른 이름 , 내 web.config에서 기본 연결 문자열은 localDB 인스턴스를 가리 킵니다.

이 문제를 어떻게 해결할 수 있습니까?

답변

0

일부 이유는 sqlServer에서 데이터베이스를 볼 수 없지만 암시 적으로 데이터베이스에 충돌하지 않았기 때문에 데이터베이스가 작성되지 않았기 때문입니다. 당신은 DB.SaveChanger(); 또는 다른 방식으로 코드에서 데이터베이스를 조회하십시오.