Nouman Bhatti
Nouman Bhatti

Reputation: 1421

EF - Code first - update database after model changes

I created a web api application in .net core 2.0 and I create my database using code first approach and using the commands add-migration , update-database

Now I made some changes in my model classes and created a new migration using add-migration 2ndMigration command. It created the migration with Up and Down methods. When I try to update database with this migration it gives me an error that

Table 'TableName' already exists.

There's no create table command in the migration.

Why I'm seeing this error? or what's the command I need to run to update the database?

Upvotes: 0

Views: 944

Answers (1)

Nick Kovalsky
Nick Kovalsky

Reputation: 6502

run Add-Migration Initial -IgnoreChanges -ConfigurationTypeName YourDbConfigurationName and add -force if needed.

After that use your regular Update-database line.

Upvotes: 1

Related Questions