---
title: "How to add or modify a model in Entity Framework Core and generate a migration for those changes."  
description: "How to add or modify a model in Entity Framework Core and generate a migration for those changes."  
author: "Utpal Vishwas"  
published: 2023-10-20  
updated: 2023-10-22  
canonical: https://www.mindstick.com/forum/160256/how-to-add-or-modify-a-model-in-entity-framework-core-and-generate-a-migration-for-those-changes  
category: ".net core"  
tags: ["asp.net core", ".net core", "database migration"]  
reading_time: 2 minutes  

---

# How to add or modify a model in Entity Framework Core and generate a migration for those changes.

How to [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) or modify a [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model) in [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) Core and generate a [migration](https://www.mindstick.com/articles/23202/magento-1-to-magento-2-migration-the-ultimate-guide-updated-2018) for those changes.

## Replies

### Reply by Aryan Kumar

To add or modify a model in [Entity](https://www.mindstick.com/forum/160562/database-connectivity-using-entity-framework-database-first-approach) [Framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) Core and generate a migration for those changes, you can follow these steps:

## 1. Add or Modify Your Model:

- Open your project and navigate to the class that represents the model you want to add or modify. Make the necessary changes to the class, which could include adding new properties, changing data types, or altering relationships with other models.

## 2. Open Package Manager Console (Visual Studio) or Command Prompt/Terminal (VS Code/CLI):

## 3. Create a Migration:

- In the Package Manager Console (Visual Studio) or your command prompt/terminal, run the following command to create a new migration. Replace **[DescriptiveMigrationName]** with a name that describes the changes you made to your model.

```plaintext
dotnet ef migrations add [DescriptiveMigrationName]
```

This command will generate a new migration file with a timestamp and the specified name in your project's Migrations folder.

## 4. Review the Migration File:

- Open the generated migration file (found in the Migrations folder of your project) using a code editor. This file contains the instructions for updating the database schema based on the changes you made to your model.

## 5. Apply the Migration:

- To apply the migration and update the database to reflect the changes in your model, run the following command:

```plaintext
dotnet ef database update
```

This command executes the SQL statements defined in the migration to make the corresponding changes to the database schema.

## 6. Verify the Database:

- After applying the migration, you can verify that the changes have been successfully applied to the database.

By following these steps, you can add or modify a model in Entity Framework Core and generate a migration that captures these changes. Migrations make it easier to evolve your database schema as your application's data model changes over time.


---

Original Source: https://www.mindstick.com/forum/160256/how-to-add-or-modify-a-model-in-entity-framework-core-and-generate-a-migration-for-those-changes

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
