Question

I have an initial create in my migrations folder alongside a subsequent migration file. When I run Update-Database -ProjectName Data -StartUpProjectName Ui -Script from the Package Manager Console I get the Sql script that would be executed should I actually execute Update-Database without the -Script attribute.

The Sql it generates contains all of the schema creation and modifications that I would expect it to but it doesn't include the INSERT statements that I would expect to be present as per my Seed method. I've tried deleting the database and letting everything get created again both via Update-Database and by setting AutomaticMigrationsEnabled = true; in my configuration.cs but regardless, I only get the schema generated, never the data.

I've obviously changed something I shouldn't have as data has been seeding just fine but has stopped this afternoon. Does anyone have any obvious suggestions for reasons why this might happen?

To confirm, I have the following method in my configuration.cs file which is unchanged from earlier today when seeding was taking place:

protected override void Seed(ContextClassHere context)
{
    // Calls to seed methods located here
}
Was it helpful?

Solution

Problem solved. I can't explain why the Seed method wasn't running but I've learnt a lot more about how to use Data-Migrations now which is a nice side-effect. I had made modifications to my model which I had scripted in a new migration file manually. It turns out I needn't have bothered as there's a tool that will do it for me, namely Add-Migration. Armed with this knowledge I rolled my model back to pre-modification, ran the InitialCreate which worked as expected with seed taking place, then ran the Add-Migration method which created the new migration file for me and now everything is working as expected again with the Seed method running every time.

I can't quite explain why the Seed method wasn't executing but everything is working as expected again now following the above process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top