Closed ojorma closed 1 year ago
What version of Microsoft.EntityFrameworkCore.Tools
are you using? Does -Verbose
give additional information?
@bricelam thanks for the response. I figured it out and posted the answer here https://github.com/aspnet/EntityFramework/issues/7540#issuecomment-286636108
Seems like https://github.com/aspnet/EntityFrameworkCore/issues/7540#issuecomment-286636108 does not work in my case
Suddenly got add-migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null ch aracter. after adding one new field to existing model.
I'm getting this as well
add-migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
PM> dotnet --version
2.0.0
not at all sure how to proceed
I think I have worked something out.
add-migration Initial
from the Package Manager ConsoleWhat works though is adding a core 2.0 console app to the solution (not editing the code) and setting that as my startup project just before running the add-migration command.
So it would seem that there's some code in the web app that gets run when the app-mrigations command is issued.
I'm guessing its the Main method...here's mine
public class Program
{
public static void Main(string[] args)
{
var host = BuildWebHost(args);
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var context = services.GetRequiredService<AdminDataContext>();
DbInitializer.Initialize(context);
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred while seeding the database.");
}
}
host.Run();
}
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
I can only assume there's something path-y going on when constructing the host that isn't working from the package manager console.
I hope this gives someone who knows better a hint as to what is going on with this.
EDIT:
It looks like something I'm doing when building my container in the Startup class's ConfigureServices method
I had the same problem with .net core 1.1 . I solved my problem by creating a console app in my solution and make it start up project. Made a reference to the project containing my written db context in the console app. Executed the 'Add-Migration Initial' with success.
Add-Migration Initial with success.
I get an error when I to run add-migration with entitcore on any dotnetcore based project but the equivalent command works when targeting the full dotnetframework
Add-Migration : Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character. Parameter name: basePath" At line:1 char:1
see a snapshot of my code. It's a dotnetcore console app. Thesame will work if created the project based on dotnetframewok 4.6.1
Steps to reproduce
Further technical details
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Operating system: IDE: (e.g. Visual Studio 2017)