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?
db.Database.EnsureCreated()
. Search your constructors andStartup
class and move them somewhere likeProgram.Main()
instead.