2017년 6월 26일 월요일

C#, MVC : EntityFramework(DBContext) 테이블 마이그레이션 초기화


MVC 테스트를 해보다 직접 테이블을 마구 수정하다보니, 마이그레이션 명령으로 테이블이 제대로 관리가 안된다.

그래서, 그냥 마이그레이션을 초기화 하고 테이블을 새로 생성.

update-database -TargetMigration:0 -force

테이블을 다 삭제 해버려 초기 상태로 만든다.

PM> update-database -TargetMigration:0 -force
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Reverting migrations: [201706211215527_FirstMigration].
Reverting automatic migration: 201706211215527_FirstMigration.

add-migration init

현재 상태를 관리포인트로 생성.

PM> add-migration init
Scaffolding migration 'init'.
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 init' again.

update-database

테이블을 업데이트한다.

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201706260304467_init].
Applying explicit migration: 201706260304467_init.
Running Seed method.