asp.net CORE迁移生成为空 [英] asp.net CORE Migrations generated empty

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

问题描述

我正在尝试遵循一个教程,以添加从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 .

WorldUser:

WorldUser :

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

WorldContext:

WorldContext :

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迁移生成为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆