1

We've been using Entity Framework Code First 5 for a little while now, without major issue.

I've recently discovered that ANY change I make to my model (such as adding a field, or removing a field) means that the Seed method no longer runs leaving my database in an invalid state.

If I reverse the change, the seed method runs fine.

I have tried making changes to varying parts of my model, so it's not the specific change which is relevant.

Anyone know how I can (a) debug what the specific issue is, or (b) come across this themselves and know how to fix it?

UPDATE: After the model change, however many times I query the database it doesn't run the Seed. However, I have found that if I manually run IISRESET, and then re-execute the web service which executes the query it does then run the seed! Anyone know why this would be the case, and why suddenly I need to reset IIS in between the database initialization and the Seed executing?

Many thanks Steve

deevodavis
  • 131
  • 1
  • 9
  • There are no errors. Anywhere. The database is created, all the tables I expect to exist do exist, but the Seed method which populates some tables isn't executed so none of the key data exists in those tables. If I comment out just that model change, drop the DB and retry it works fine. As I said as well, I am 100% sure that the model change is valid as it's literally a complete copy of a field which already exists and I've just changed the name to make it unique. I've tried other tables as well, so it's not just that one table. – deevodavis Feb 01 '13 at 18:17
  • have you tried to `custom run tool` the model? http://stackoverflow.com/a/14532189/1080742 – spajce Feb 01 '13 at 20:25
  • I mentioned that I am using EF Code First, so am not sure this is relevant? – deevodavis Feb 01 '13 at 20:48
  • are you generating your database from your models? An invalid seed means you need to regenerate the DB - which is needed if you change the model. – Charles Feb 01 '13 at 23:14
  • I am using the MigrateDatabaseToLatestVersion initializer which performs the migration automatically, and which has worked seemlessly until now. I have also tried getting EF to create the DB from scratch (as you say) which works fine prior to any changes, and after the change creates the DB structure OK but just fails to run the seed (until I manually IISRESET as I specified in the UPDATE above). – deevodavis Feb 02 '13 at 03:13

0 Answers0