asp.net CORE Migrations generated empty(asp.net CORE Migrations 生成为空)
问题描述
我正在尝试按照教程添加从 IdentityDbContext
和 IdentityUser
生成的迁移(第二个).
当我运行 dotnet ef migration add <NAME>
时,它正在添加,但 UP
和 DOWN
为空.
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 生成为空
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01