CodeFirst Approach. I have a multi project solution. My Projects are structured by. AccessService, ModelService and the ProjectName for the razorpages and rest of the code. TestDb: I have an existing database and Migration called TestDb. I want to update my Migration then Update the database for any edit or new models which the db needs to save.
The a migration has multple models in the table, Student is one of them. The Table Student has: Student Id student name, I want to add StudentGrade to the Student table. So the table Student has a new field Grade. Another example would be. I want to add the Model Class Room. It does not exist in the original migration or db. I want to add it to the DB so it holds a new table ClassRoom.
I have FramewWorkCore.tools(6.0.13), same version for sqlServer. When i use these commands i just get errors. I've tried Force, IgnoreChanges and f. I solved one large problem. Now i got another.
Your target project 'ProjectPortal' doesn't match your migrations assembly 'ProjectAccessService'. 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("ProjectPortal")). 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.
So my understanding is, i need to somehow tell entityframework to change the target to AccessService
Here's the solution. This is meant for multiple projekts. If you have an AccessService and a AllProjekt like i do, You need to add this.
builder.Services.AddDbContext<DbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("AuthConnectionString"),
b => b.MigrationsAssembly("ProjektAccessService")));
ProjektAccessService is the name of your Solution/projekt. You do not start a Migration before adding this. If your migratet your before adding this, i can't help you.
I added this, then i started my first Migration. Updated the database. Tried my 2nd Migration, updated the database. It works. Is it a solution for all. deferentially not. Is it dumb, 100%.