I had multiple startup projects in a clean architecture, ProjectA.API and ProjectA.UI. The project that handles DBContext is ProjectA.Infrastructure. I corrected this issue with the following steps:
Make the API project the only startup project since it interacts with the infrastructure layer alone.
Add Microsoft.EntityFrameworkCore.Design package to the API project and ensure that the version you are using is the same as Microsoft.EntityFrameworkCore.SqlServer in the infrastructure project.