Entity Framework Seed method is not being called

后端 未结 1 574
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 01:12

We are using Entity Framework 4.4 and using migrations. The database already exists and we need to update it on regular basis. The seed method, however, is not being called

相关标签:
1条回答
  • 2021-01-02 01:51

    The Migrations Seed method

    runs whenever the Update-Database PowerShell command is executed

    You need to call Update-Database not Add-Migration

    Add-Migration scaffolds a migration file containing commands to migrate the database to a new version. It is empty because there are no schema changes to make. You do not need to call Add-Migration before calling Update-Database if all you want to do is seed

    References:

    Code first Db initialization strategies.
    Code first migrations recommended reading
    Managed Migrations
    Database initializer and Migrations Seed methods

    0 讨论(0)
提交回复
热议问题