Bốn lệnh cơ bản của dotnet ef:
bash
dotnet ef migrations add AddOrderTable # scaffold migration from model diff
dotnet ef database update # apply all pending migrations
dotnet ef migrations list # show applied / pending
dotnet ef migrations remove # delete the LAST migration (must be unapplied)Quay lui: database update nhận tên migration đích.
Đưa tên migration trước cái muốn bỏ, EF sẽ chạy phần Down():
bash
dotnet ef database update AddCustomerTable # roll back to this point
dotnet ef migrations remove # now safe to delete the reverted file
dotnet ef database update 0 # revert everythingThứ tự quan trọng: migrations remove chỉ xoá được migration chưa apply. Nếu đã apply mà xoá file trước, model snapshot lệch với DB và lần add sau sẽ sinh migration sai.
Với production, đừng gỡ migration đã chạy — viết một migration mới đảo lại thay đổi. Deploy thường dùng dotnet ef migrations script --idempotent để sinh script SQL cho DBA duyệt thay vì chạy database update trực tiếp.