How to Perform a Migration
How to Perform a Migration 관련
Migrations allow you to update the database schema based on changes made to your model classes. In Entity Framework Core, you can use the dotnet ef migrations add
command to create a new migration reflecting these changes.
To perform a migration, run the following command in the terminal:
dotnet ef migrations add InitialCreate
If the command is successful, you should see an output similar to this:
Build started...
Build succeeded.
Done. To undo this action, use 'ef migrations remove'
You will now see a new folder called Migrations
in your project. This folder contains the migration files that were created based on the changes made to your model classes. These migration files include the SQL commands required to update the database schema.
How to Update the Database
After creating the migration, you need to apply the migration to update the database schema. You can use the dotnet ef database update
command to apply the migration and update the database. Make sure the SQL Server is running.
Run the following command in the terminal:
dotnet ef database update
This will update the database schema based on the changes made to your model classes. Make sure there are no errors on your database connection string.