I am using Entity Framework 6.3 for an MVC 5 application, using code-first (for the first time) with SQL Server 2012. The Database does not exist before hand, it is all being created from scratch by EF. When I attempt to start the application, and hence EF should create the database, it's giving me the following SqlException error message:
"There is already an object named 'TableName' in the database."
I have in my project the following very basic Entity:
[Table("TableName")]
public class ItemStatus
{
public int id { get; set; }
public string Status { get; set; }
}
That's all it is.
If I change the name of TableName to something else, like foofoo, then the error message reflects this change. So I've not put two Models in with the same table name or anything obvious like that.
Everything had been working fine until just recently, I'm not sure what I could have changed to make it break like this. The last thing I did before it stopped working was add a new View Model. Removing this completely doesn't help.
Additional information 1: My solution has two projects, each with a DbContext. DbContext2 from Project2 inherits from DbContext1 from Project1 - which in turn is inheriting from IdentityDbContext. I was thinking that maybe this has something to do with it? Like both projects are trying to Create the same table for some reason. Although I'm pretty sure it should check if the table exists or not before trying to create it.
Additional Information 2: When I look at the Database server after getting this error, I see that it has created multiple other tables from entities in Project1 with no apparent problems.
Additional Information 3: If I hadn't made it clear yet, it was working fine earlier today. I've had that Entity in my project for a while with no problems, and I'd not changed anything about it before getting this error.
Thanks in advance for any advice.
Edit: I should have mentioned that I'm using MigrateToLatestVersion as my initialization. I don't get the problem if I use DropCreateDatabseAlways.