Asp.Net 核心如何将迁移类型配置为程序集
Asp.Net Core How to Configure Migrations type to assembly
大家好,我叫 Taniguchi,我正在学习 asp.net 核心,我设法创建了一个迁移,但是当我使用 Update-Database 命令时,显示以下错误:“
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No migrations configuration type was found in the assembly 'WebApplication1'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
我的数据库:
public class MimicContext : DbContext
{
public MimicContext(DbContextOptions<MimicContext> options) : base(options)
{
}
public DbSet<Palavra> Palavras { get; set; }
}
我的创业公司:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MimicContext>(opt =>
{
opt.UseSqlite("Data Source=Database\Mimic.db");
});
services.AddMvc(options => options.EnableEndpointRouting = false);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
如何配置到程序集的迁移?
您是否在您的项目中启用了迁移?如果你没有,那就使用 Enable-Migrations。我认为这可能是问题所在。
在 运行 之前,PMC 中的 update 命令首先启用它。有关详细信息,请查看此 link here
小错误,但经过一天多的痛苦努力后,对我来说是很好的学习。我希望这对其他人来说也是很好的学习。
我添加了两个 NuGet 包:EntityFramework 和 Microsoft.EntityFrameworkCore,这是我的错误。
只需为 Microsoft.EntityFrameworkCore 添加 NuGet 包即可完成所有必需的工作。
大家好,我叫 Taniguchi,我正在学习 asp.net 核心,我设法创建了一个迁移,但是当我使用 Update-Database 命令时,显示以下错误:“
Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No migrations configuration type was found in the assembly 'WebApplication1'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
我的数据库:
public class MimicContext : DbContext
{
public MimicContext(DbContextOptions<MimicContext> options) : base(options)
{
}
public DbSet<Palavra> Palavras { get; set; }
}
我的创业公司:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MimicContext>(opt =>
{
opt.UseSqlite("Data Source=Database\Mimic.db");
});
services.AddMvc(options => options.EnableEndpointRouting = false);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
如何配置到程序集的迁移?
您是否在您的项目中启用了迁移?如果你没有,那就使用 Enable-Migrations。我认为这可能是问题所在。
在 运行 之前,PMC 中的 update 命令首先启用它。有关详细信息,请查看此 link here
小错误,但经过一天多的痛苦努力后,对我来说是很好的学习。我希望这对其他人来说也是很好的学习。
我添加了两个 NuGet 包:EntityFramework 和 Microsoft.EntityFrameworkCore,这是我的错误。
只需为 Microsoft.EntityFrameworkCore 添加 NuGet 包即可完成所有必需的工作。