Reputation: 3364
I'm using Entity Frame work 5 code first in my website. Every thing was fine and I've been using
update-database -verbose
to update database with new data or new structure and model, however; out of no where update-database has stopped working and it doesn't track changes in model and new tables anymore.
I have searched over internet and some say that I have to delete database context and recreate it to make it work. I can't do this, the project is kind of big and more than 4k lines would be affected if I delete the database context.
I'm using visual studio 2012 with the 3rd update, so update is not the solution either.
any suggestions.
Upvotes: 3
Views: 12909
Reputation: 51
From your Migration file which is created right after the 'Add-Migration 'migrationname' ' command. Check the changes that it has listed. Keep that much and remove the other things. For example, it could be recreating all your tables in the 'Up' method and deleting tables in the 'Down' method. Remove all the unwanted changes and save the file. Then do an 'update-database' command in the PM Console.
Upvotes: 0
Reputation: 41
I'm no expert by any means but my tables weren't created with the PM> Update-Database command so I:
And your tables and columns will appear. This worked for me. Again I am a newb just figuring stuff out.
Upvotes: 4
Reputation: 21
Sometimes they dont generate as they dont get registerd correctly in the IdentityModels.cs file.
Just after the context creation method
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
Add the class registration
public System.Data.Entity.DbSet<PROJECT.Models.MODELNAME> MODELNAME { get; set; }
Build the project and run update-database -verbose (the -verbose switch will show the updates made)
Upvotes: 2
Reputation: 3364
as I told you deleting the database context didn't fix my problem. This is how I fixed the issue. I dropped table __MigrationHistory using sql command and run the update-database -verbose again.
Apparently something was wrong with this automatic created table.
Upvotes: 5