[英]Microsoft.EntityFrameworkCore.SqlServer - Database not updating on context.Database.Migrate();
I'm trying to move a project from using Dapper to Microsoft.EntityFrameworkCore.SqlServer.我正在尝试将一个项目从使用 Dapper 转移到 Microsoft.EntityFrameworkCore.SqlServer。
I've created the entities and their respective mappings(configurations).我已经创建了实体及其各自的映射(配置)。
Also I'm running in my ConfigureServices method inside startup.此外,我在启动时使用我的 ConfigureServices 方法运行。
using var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
using var context = scope.ServiceProvider.GetRequiredService<SpannerContext>();
context.Database.EnsureCreated();
context.Database.Migrate();
But nothing is happening;但是什么也没有发生;
Logs shows:日志显示:
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
But I've added some new DbSets and also change some column types但是我添加了一些新的 DbSets 并且还更改了一些列类型
Am I missing something?我错过了什么吗?
try to generate your models and configuration form an existing database, then apply the modifications/changes in your models.尝试从现有数据库生成模型和配置,然后在模型中应用修改/更改。
https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx
I order to solve the problem i followed the following steps我为了解决问题我遵循了以下步骤
The new migration should work as expected;新迁移应该按预期工作;
This way you don't need to comment the up part of the code;这样你就不需要注释代码的up部分;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.