C
C#4mo ago
Tiltyboi

EF-Core migrations issue

I have split a large project into multiple places. I have 1 class-library with my classes and contexts, 1 class library where my migrations will go and then my main app. When i do Add-Migration init -Project <lib-with-context> it throws this lovely error:
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[SadBot.Core.Database.RPGContext]' while attempting to activate 'SadBot.Core.Database.RPGContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[SadBot.Core.Database.RPGContext]' while attempting to activate 'SadBot.Core.Database.RPGContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
1 Reply
Tiltyboi
TiltyboiOP4mo ago
On further investigation might have been a db connection string issue. Re-running the command after testing the connStr gives me a new error:
Your target project 'SadBot.Core' doesn't match your migrations assembly 'SadBot.Migrations'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("SadBot.Core")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project
Your target project 'SadBot.Core' doesn't match your migrations assembly 'SadBot.Migrations'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("SadBot.Core")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project
Want results from more Discord servers?
Add your server