코드 첫 번째 마이그레이션은 localdb에서 잘못된 DB를 업데이트합니다
-
21-12-2019 - |
문제
코드 첫 번째 마이그레이션을 사용하여 My ASP MVC 사이트의 데이터베이스를 만들고 업데이트합니다.
솔루션의 다른 프로젝트에있는 DBContext가 있습니다.
public class EFDbContext : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Publisher> Publishers { get; set; }
}
.
이 마이그레이션 및 추가 마이그레이션 [이름] 을 활성화 할 때
.
라는 자체 DB를 만드는 것 같습니다.[foo-projectname].Domain.Concrete.EFDbContext
.
[foo-projectName] 이라는 [foo-projectname] 이라는 데이터베이스에 첨부하는 대신. 사이트의 WebConfig에서 연결 문자열은 " [foo-projectName] "카탈로그에 의해 참조됩니다.
WebConfig를 다른 데이터베이스로 변경하면 해당 데이터베이스에 추가 된 항목에서 결과를 가져옵니다. 그러나 내가 만든 데이터베이스를 사용하고 싶습니다.
이 자동 생성 된 이유는 SQLServer 로의 마이그레이션에 확실하지 않고 줄을 더 멈추고 싶지 않기 때문입니다. 나는 또한 오류를 얻고있다
'efdbContext'컨텍스트를 백업하는 모델은 이후로 변경되었습니다 ...
아무것도 바꾸지 않을 때에도.
해결책
x는 파생 된 DbContext
클래스를 포함하는 프로젝트 이름입니다.
-
Default project
의Package Manager Console
가 x 인지 확인하십시오.
- 솔루션의 활성 시작 프로젝트가 X 인지 확인하십시오.
다른 해결 방법은 마이그레이션 구문을 실행할 때 다음 매개 변수를 제공합니다.
-ProjectName X -StartUpProjectName X
.
일부 매개 변수 설명 :
-ProjectName <String>
Specifies the project that contains the migration configuration type to be
used. If omitted, the default project selected in package manager console
is used.
-StartUpProjectName <String>
Specifies the configuration file to use for named connection strings. If
omitted, the specified project's configuration file is used.
-ConfigurationTypeName <String>
Specifies the migrations configuration to use. If omitted, migrations will
attempt to locate a single migrations configuration type in the target
project.
-ConnectionStringName <String>
Specifies the name of a connection string to use from the application's
configuration file.
-ConnectionString <String>
Specifies the the connection string to use. If omitted, the context's
default connection will be used.
. 제휴하지 않습니다 StackOverflow