Hi,
I am using VSCode and I am struggling to migrate my database with ef as I have already installed the necessary dotnet packages.My problem is that every time i am trying to do "
sudo dotnet ef migrations add InitialCreate
" it will not complete the process as it says I have a null connectionString parameter(
System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
).I double checked my db string connection which is the following in my appsettings.json:
"
"ConnectionStrings ": {
"DataContext": "host=localhost;port=3306;user id=****;password=*******;database=*****;"
}
"
In the Startup.cs class I have the following:
public void ConfigureServices(IServiceCollection services)
{
var connectionString = Configuration.GetConnectionString("DataContext");
services.AddDbContext<DataContext>(options => options.UseMySql(connectionString));
services.AddControllersWithViews();
}
Now I don't understand why it's not working since the name is correct along with the syntax in the appsettings.json.I am aware that MySql.Data is not the best solution for migration so instead i am using pomelo.This is my project.csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="3.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
</ItemGroup>
Any help would be appreciated!
What I have tried:
I have tried to change the code in Startup.cs as follows:
"
services.AddDbContext<DataContext>(options => options.UseMySql(Configuration.GetConnectionString("DataContext")))
"
Except this,I don't know what else i could try since the connection is correct and the same code worked before...