asp.net CORE Migrations 生成为空

asp.net CORE Migrations generated empty(asp.net CORE Migrations 生成为空)

本文介绍了asp.net CORE Migrations 生成为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照教程添加从 IdentityDbContextIdentityUser 生成的迁移(第二个).
当我运行 dotnet ef migration add <NAME> 时,它正在添加,但 UPDOWN 为空.

I'm trying to follow a tutorial to add a migration(a second one) generated from IdentityDbContext and IdentityUser .
When I run dotnet ef migration add <NAME> it being add, but UP and DOWN are empty.

我发现从 EFMigrationHistory 表中删除数据可以解决问题,但该表不包含有关该迁移的任何信息,仅包含已创建的第一个.我尝试删除所有 .TMP 文件,删除并重新创建迁移.

I found that deleting the data from EFMigrationHistory table can solve the problem, but the table doesn't contain any information about that migration, only on the first one that was already created. I tried deleting all the .TMP files, drop and recreate the migration .

世界用户:

namespace TheWorld.Models
{
    public class WorldUser : IdentityUser
    {
        public DateTime FirstTrip { get; set; }
    }
}

世界语境:

namespace TheWorld.Models
{
    public class WorldContext : IdentityDbContext<WorldUser>
    {
        private IConfigurationRoot _config;
        public WorldContext(IConfigurationRoot config,DbContextOptions options) : base(options)
        {
            _config = config;
        }
        ....

奇怪的是,它昨天没有用,今天早上我尝试删除所有 .TMP 文件,迁移,并通过 CMD 重新创建它,它生成了一个看起来正确的迁移,但愚蠢的是,我删除它是因为它的名称错误,并且重新创建后它不再起作用.

The weird thing is, it didn't work yesterday, and today morning I tried deleting all the .TMP files, the migrations, and recreate it via the CMD, and it generated a migration that looked correct, but stupidly, I deleted it because it had the wrong name, and since recreated it doesn't work again .

推荐答案

您的迁移文件夹应该包含一个 WorldContextModelSnapshot.cs,该文件包含整个数据库的定义.如果模型已在此文件中定义,它将不再出现在新的迁移中.

Your migrations folder should contain a WorldContextModelSnapshot.cs, this file contains a definition for the entire database. If the model is already defined in this file, it will no longer appear in new migrations.

如果您想再次生成迁移,请从该文件中删除模型并再次生成迁移.

If you want to generate the migration again, remove the model from this file and generate your migration again.

这篇关于asp.net CORE Migrations 生成为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:asp.net CORE Migrations 生成为空

基础教程推荐