Issue
I am trying to create a migration in an ASP.NET Core Web Application, but when I try to do it, the package manager console returns a warning and an error:
Warning: "A version of Entity Framework older than 6.3 is also installed. The newer tools are running. Use 'EntityFramework\Add-Migration' for the older version."
Error: "No migrations configuration type was found in the assembly 'MyProjectName'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration)."
After doing some research I have found that a common problem is that the default project chosen in the package manager is not correct; but this is not my case, since it only gives me one option, and it is the project with which I am working. I have also found that a current solution is to enable the migrations with the "Enable-Migrations" command, but when I try to do this, it gives me the same warning and another error:
error: No context type was found in the assembly 'MyProjectName'.
I have also tried it the "enable-migraitons" command in a different way, "enable-migrations -contexttypename MyDBContextName", but this gives me another error:
error: The context type 'MyDBContextName' was not found in the assembly 'MyProjectName'.
But I actually have the following class:
public class MyDBContextName: IdentityDbContext<UserModel>
{
public MyDBContextName(DbContextOptions<MyDBContextName> options) : base(options)
{
}
}
And I have this in my startup/configure services class:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyDBContextName>(options => options.UseSqlServer("DefaultConnection"));
services.AddIdentity<UserModel, IdentityRole>().AddEntityFrameworkStores<MyDBContextName>().AddDefaultTokenProviders();
services.AddControllers();
}
Lastly, is a picture of my NuGet packages:
Any Idea of what may be causing these errors? Thank you so much for your time, if you need more information I will provide it to you ass soon as I see your request. Have a good day. (:
Solution
I still don't know what caused those errors, but after some changes I can now create migrations. Here are the 3 changes that I made:
I installed Microsoft.EntityFrameworkCore.Tools
I changed
services.AddDbContext<MyDBContextName>(options => options.UseSqlServer("DefaultConnection"));
for
services.AddDbContext<MyDBContextName>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
- Finally, in my app.setting.json I changed
"connectionStrings":
{
"DefaultConnection": "Data Source=MyName;Initial Catalog=PracticaApiSecurity;Integrated Security=True"
},
for
"connectionStrings": {
"DefaultConnections": "Data Source=MyName;Initial Catalog=PracticaApiSecurity;Integrated Security=True"
},
changed connection for connectionS
Answered By - Jaime Santos Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.