Reputation: 117
I want to apply a migration on my server but I got an error which asks me to specify the project but when I specify the project I get an another error.
However they work in development.
Here's the first error:
dotnet ef database update
No project was found. Change the current working directory or use the --project option.
And here, the second:
dotnet ef database update --project Devystri
/var/www/devystri/Devystri(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
Here my migrations files:
Thank you !
Upvotes: 0
Views: 722
Reputation: 117
The solution is to add this in the Program.cs:
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<MyDbContext>();
try
{
db.Database.Migrate();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
host.Run();
}
Upvotes: 1