ASP.NET MVC 4와 Entity Framework 5.0을 사용하여 응용 프로그램을 작성하고 있습니다. 필자는 데이터베이스 용 응용 프로그램에 구현할 수있는 EF 코드 - 첫 번째 마이그레이션 도구에 대해 최근에 배웠습니다. PM 콘솔에서 "Enable-Migration"을 실행하고 성공적으로 활성화하고 테이블 생성으로 채워진 적절한 up() 및 down() 메소드로 예상대로 "InitialCreate.cs"클래스를 생성했습니다.Entity Framework 코드 처음 마이그레이션 클래스 파일
그런 다음 두 가지 간단한 속성 (id, name)을 사용하여 다른 클래스 (Category.cs)를 추가하고이 마이그레이션을 데이터베이스에 추가하려고했습니다. (
Scaffolding migration 'AddCategoryClass'.
The Designer Code for this migration file includes a snapshot of your current Code
First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration 201307301938256_AddCategoryClass' again.
그것은 마이그레이션 폴더에 마이그레이션 파일을 만들었지 만이 ".cs"를 열 때까지,이 생성 된 파일 : 나는이 메시지가 내 PM에 "AddCategoryClass 마이그레이션 추가"실행) 및 Down() 메서드는 비어 있습니다. 나는 그것이 테이블을 만들고 필드를 각각 추가 할 것을 기대하고 있었다. 호기심에서 "Update-Database"를 실행하고 Configuration.cs 파일에서 AutomaticMigration = true를 변경 한 후 성공적으로 통과했습니다. 응용 프로그램을 만들 때 테이블이 데이터베이스에 나타났습니다.
내 질문은 -> 왜 Up() 및 Down() 메소드가 비어 있습니까?
Configuration.cs 파일에서 AutomaicMigrations = false 인 경우 "Update-Database"명령이 작동하지 않습니다.
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
나는이 값이 주어져서는 안된다고 가정하고 있으며, 나중에 마이 그 레이션을보고 내가 한 것을 볼 때 도움이 될 것입니다. 어떤 도움이나지도라도 도움이 될 것입니다. 미리 감사드립니다.
Win 7 64bit에서 VS 2012를 사용하고 있습니다.
하나 이상의 마이그레이션 파일 (configuration.cs 제외)이 있습니까? – SOfanatic
지금은 InitialCreate와 AddCategoryClass 두 가지를 보여줍니다. 하지만 두 번째 것은 빈 메소드를 가지고 있습니다. – Sixers17
은 설정 클래스에서'AutomaticMigrationsEnabled = true'입니까? –