Add an implementation of 'IDesignTimeDbContextFactory' to the project error while creating a migration step in .NET core 2.0

后端 未结 3 839
無奈伤痛
無奈伤痛 2020-12-18 06:51

I had a .NET core 1.0 webapp working fine. I had to upgrade to .NET Core 2.0. I also had to add a migration step for my SQLite database.

If I launch this command:

3条回答
  •  别那么骄傲
    2020-12-18 07:19

    A possible solution to IDesignTimeDbContextFactory<> problem is the DBContext discovery/launch during the add-migration process. Add migrations needs to get a context. If it cant, this error is thrown. This can happen if you do not have a public parameter-less DBContext. So a solution is to Add a public Parameter-less constructor to your context.

    public  class SomeDbContext: DbContext
    {
        // this PUBLIC constructor  is required for Migration tool
        public SomeDbContext()
        {
    
        }
      // the model...
        public DbSet PocoBlas { get; set; }
        ....
     }
    

    You can have a special version of your DBContext in a separate project .netCore console project for migration code generation purposes.

提交回复
热议问题