【问题标题】:Entity framework core doesn't create migration file实体框架核心不创建迁移文件
【发布时间】:2017-01-25 15:53:30
【问题描述】:

我已经完成了我的模型结构并运行了

sudo dotnet ef 迁移添加 3-MyMigration

命令,但没有在 Migration 文件夹中创建文件。

这是输出:

 Project SocioFal (.NETCoreApp,Version=v1.0) will be compiled because project is not safe for incremental compilation. Use --build-profile flag for more information.
 Compiling SocioFal for .NETCoreApp,Version=v1.0
 Bundling with configuration from /home/aymeric/dotnet_projects/sociofal/SocioFal/bundleconfig.json
 Processing wwwroot/css/site.min.css
 Processing wwwroot/js/site.min.js
 Compilation succeeded.
    0 Warning(s)
    0 Error(s)
 Time elapsed 00:00:04.0311963
 (The compilation time can be improved. Run "dotnet build --build-profile" for more information)

并带有详细标签:

Project SocioFal (.NETCoreApp,Version=v1.0) will be compiled because project is not safe for incremental compilation. Use --build-profile flag for more information.
Compiling SocioFal for .NETCoreApp,Version=v1.0
Bundling with configuration from /home/aymeric/dotnet_projects/sociofal/SocioFal/bundleconfig.json
Processing wwwroot/css/site.min.css
Processing wwwroot/js/site.min.js
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:13.1481501
(The compilation time can be improved. Run "dotnet build --build-profile" for more information)
Setting app base path /home/aymeric/dotnet_projects/sociofal/SocioFal/bin/Debug/netcoreapp1.0
Finding DbContext classes...
Using context 'ApplicationDbContext'.

所以没有显示错误。

这里是使用的上下文:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public DbSet<GenealogyRelation> GenealogyRelation { get; set; }

    public DbSet<FalEvent> FalEvent { get; set; }
    public DbSet<GenealogyFalEvent> GenealogyFalEvent { get; set; }
    public DbSet<BaptemeFalEvent> BaptemeFalEvent { get; set; }

    public DbSet<AdoptionFalEvent> AdoptionFalEvent { get; set; }

    public DbSet<ConfirmationFalEvent> ConfirmationFalEvent { get; set; }


    public DbSet<GenealogyCityAndFieldFalEvent> GenealogyCityAndFieldFalEvent { get; set; }


    public DbSet<City> City { get; set; }
    public DbSet<FalProfile> FalProfile { get; set; }
    public DbSet<SocialProfile> SocialProfile { get; set; }

    public DbSet<StudyField> StudyField { get; set; }
    public DbSet<UserStudyField> UserStudyField { get; set; }

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        builder.Entity<GenealogyFalEvent>().ToTable("GenealogyFalEvent");
        builder.Entity<BaptemeFalEvent>().ToTable("BaptemeFalEvent");
        builder.Entity<ConfirmationFalEvent>().ToTable("ConfirmationFalEvent");
        builder.Entity<AdoptionFalEvent>().ToTable("AdoptionFalEvent");
        base.OnModelCreating(builder);
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);
        builder.Entity<GenealogyRelation>().HasKey((e) => new {e.ChildID, e.GenealogyFalEventID, e.ParentID});
        builder.Entity<UserCity>().HasKey(u => new {u.CityID, u.UserID});
        builder.Entity<UserStudyField>().HasKey(u => new {u.StudyFieldID, u.UserID});

    }
}

为什么 EF Core 不创建迁移文件?

【问题讨论】:

  • 您可以尝试使用 -verbose 标志运行上述命令并发布该输出吗?
  • “使用上下文'ApplicationDbContext'”后没有输出?这可能表明生成迁移的代码仍在运行(可能陷入无限循环)
  • 我没有考虑过,因为在那之后命令行没有被阻止,我编辑了我的问题,以便您可以看到 ApplicationDbContext 代码,不知道 EF Core 是否因复合而崩溃我用过的钥匙?
  • 这里似乎没有什么问题。你能在github.com/aspnet/EntityFramework 上提交一个带有步骤和模型类的完整重现的错误吗?
  • 你有没有弄清楚问题是什么 - 我有同样的问题......

标签: c# asp.net asp.net-core .net-core entity-framework-core


【解决方案1】:

您的模型真的需要迁移吗?如果自上次迁移后未对其进行修改,则 ef 可能不需要生成迁移。

虽然只是猜测,但不确定。

【讨论】:

  • 是的,我为我的模型创建了一个新结构,因此在我的上下文中有新的属性。我做了一个 dotnet ef 数据库删除,但它没有生成用于重新创建数据库的文件。
猜你喜欢
  • 2020-06-21
  • 1970-01-01
  • 2021-06-27
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-06
  • 2019-11-08
  • 2022-01-28
相关资源
最近更新 更多