1

I am working on asp.net core and using EF. I have created database from scratch using EF. Now whenever there are changes in the database, adding new columns, or changing the type etc. Then I run the Update-datebase migration but I am getting an error for having tables and other object in database. Can someone help me what changes would I need to make in order to make the migration successful?

The compile error mentioned that the object already exists. Lets say if I have customer table that is already created in the database, when I run the script again after adding new object or modification, I am getting that error, this does make sense but what is the common practice to deal with the issue?

2
  • 1
    what is the error? Commented Jun 8, 2021 at 8:29
  • vivek nuna: I have updated the question. Commented Jun 9, 2021 at 5:59

1 Answer 1

1

As described in Migrations Overview after you are evolving your models (adding properties, removing properties, editing them and etc...) you need to update your database schema, in order to do that, you are required to add a new migration.

This can be possible in the one of following ways:

  1. via .NET CLI

    dotnet ef migrations add NewMigrationName 
  2. via PowerShell

    Add-Migration NewMigrationName 

After adding a new migration you just need to sync the database by:

Update-Database 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.