Can't use migrations in EF Core: "42P07: relation "AspNetRoles" already exists" Can't use migrations in EF Core: "42P07: relation "AspNetRoles" already exists" postgresql postgresql

Can't use migrations in EF Core: "42P07: relation "AspNetRoles" already exists"


The reason was pretty simple.I was calling EnsureCreated in Startup.cs which was getting conflict with migrations as working different way.Thankfully EF Core owners made it clear for me on GitHub.

So to summarize - if you want to use Migrations, you can't use EnsureCreated.


I was doing something really dumb! I copied the connection string from another micro service and it had the wrong Database in the connection string - that database already had the table that the error was complaining about! Block Copy strikes again!