This guide covers the full workflow for local database setup, Git branching, and creating Entity Framework migrations. Following these steps will help prevent conflicts and maintain a clean project history.
Create the database and apply all existing migrations.
dotnet ef database updateFollow this process before you create a new migration to ensure your branch is up-to-date with the main branch. This is the standard workflow to prevent conflicts.
-
Commit Your Current Work: Make sure any changes on your feature branch are committed.
git add . git commit -m "Your work-in-progress commit message"
-
Sync with the
mainBranch:- Switch to
mainand pull the latest changes.git checkout main git pull origin main
- Switch back to your feature branch and rebase it on top of
main.git checkout your-feature-branch git rebase main
- Switch to
-
Apply Your Team's Migrations: After rebasing, your project might now include new migrations from your teammates. Apply them to your local database.
dotnet ef database update
-
Create Your New Migration: Now that your local database is synced with the latest schema, you can safely create your own migration.
dotnet ef migrations add <DescriptiveMigrationName>
-
Commit the New Migration: The previous command created new files. You must add and commit them.
git add . git commit -m "feat: Add migration for <DescriptiveMigrationName>"
-
Apply Your Own Migration: (Optional but recommended) Test your new migration by applying it to your local database.
dotnet ef database update