---
title: "How to create an initial migration for a database using Entity Framework Core?"  
description: "How to create an initial migration for a database using Entity Framework Core?"  
author: "Utpal Vishwas"  
published: 2023-10-20  
updated: 2023-10-22  
canonical: https://www.mindstick.com/forum/160252/how-to-create-an-initial-migration-for-a-database-using-entity-framework-core  
category: ".net core"  
tags: ["asp.net core", ".net core", "database migration"]  
reading_time: 2 minutes  

---

# How to create an initial migration for a database using Entity Framework Core?

How to create an initial [migration](https://www.mindstick.com/articles/23202/magento-1-to-magento-2-migration-the-ultimate-guide-updated-2018) for a [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) using [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) Core?

## Replies

### Reply by Aryan Kumar

Creating an initial migration for a database using [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 involves using the Entity Framework Core CLI or Package Manager Console to generate a migration that captures the current state of your data model. Here are the steps to create an initial migration:

**1. Install Entity Framework Core Tools (if not already installed):** If you haven't installed the Entity Framework Core Tools, you can do so using the following command:

```plaintext
dotnet tool install --global dotnet-ef
```

**2. Create or Verify Your Data Model:** Ensure that you have defined your data model using C# classes. These classes should represent the tables, relationships, and properties in your database.

**3. Navigate to Your Project Directory:** Open a command prompt, terminal, or Package Manager Console in Visual Studio. Navigate to the root directory of your project, where your DbContext is defined.

**4. Run the Migration Command:** Use the Entity Framework Core CLI to create an initial migration. Replace **[DescriptiveMigrationName]** with a name that describes this migration, typically something like “InitialCreate.”

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

Example:

```plaintext
dotnet ef migrations add InitialCreate
```

**5. Review the Generated Migration:** The **dotnet ef migrations add** command will create a migration file in your project's "Migrations" folder. This file contains the instructions to create the database schema based on your data model.

**6. Apply the Migration (Update the Database):** After generating the migration, you can apply it to create the initial database schema using the following command:

```plaintext
dotnet ef database update
```

This command will execute the SQL statements in the generated migration to create the database and tables based on your data model.

**7. Verify the Database:** You can verify that the database has been created and populated with the initial schema by inspecting the database or using tools like SQL Server Management Studio or a database viewer.

After completing these steps, you will have created an initial migration that captures the current state of your data model and applied it to generate the corresponding database schema. This sets up your database for use with Entity Framework Core.


---

Original Source: https://www.mindstick.com/forum/160252/how-to-create-an-initial-migration-for-a-database-using-entity-framework-core

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
