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 生成为空
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
