0

I am trying to add a migration in another project and I am literally getting white hair here trying different solutions found everywhere and none work, I just don't understand why isn't working.

I have this in Startup.cs

 services.AddDbContext<ApplicationDbContext>(
            c => c.UseSqlServer(_config.GetConnectionString("ApplicationDbContext"), 
            opt => opt.MigrationsAssembly("DatabaseContext.Migrations")));

I did check this, this, this and I think a few others, I don't know whats wrong.

For my solution structure is the following:

Shop (former empty solution)
1. DatabaseSchema (folder with empty spaces)
DatabaseContext (project with the migrations folder inside)
..
bunch of other stuff
..
ShopApi (here I have that code above in Startup.cs)

I tried:

dotnet ef migrations add ExampleMigration -s ../ShopAPI dotnet ef migrations script --project DatabaseContext --startup-project ../ShopAPI

It simply says there is no project found, I don't understand whats wrong with the path, I go one folder up and the project is right there. As it gets extremely annoying and on my nerves I tried all combinations of paths and still not finding anything.

The path is like this:

Shop (Solution) -> 1. DatabaseSchema (Folder) -> DatabaseContext/Migrations
                -> ShopAPI (is where I have my Startup.cs)

What I don't understand here?

Eduard
  • 732
  • 1
  • 7
  • 20

1 Answers1

0

Yea ok, I solved this after all I used this command instead

Add-Migration Subcategory_Entity_Added -StartupProject ShopAPI

On Package manager console I set up the migration parent project.

And I removed MigrationsAssembly portion because the command above gave a different error:

Could not load file or assembly 'DatabaseContext.Migrations, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

So I guess it read the path as.. looking for a specific file because of the '.', I am not sure, I removed everything and tried it.

Eduard
  • 732
  • 1
  • 7
  • 20