【发布时间】:2021-11-12 19:09:23
【问题描述】:
我正在尝试为我的数据库进行迁移以添加一列。我设置了迁移,一切看起来都很好。我运行了命令,它抓取了正确的迁移并将其运行到数据库中,但它没有显示在数据库中。
我的迁移:
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Mudman.Data.Migrations
{
public partial class AttachedFileFileCategory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "FileCategory",
table: "AttachedFile",
type: "nvarchar(max)",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FileCategory",
table: "AttachedFile");
}
}
}
我的命令终端:
数据库:
【问题讨论】:
-
您确定这是正确的数据库吗?另外,您是否刷新了用于连接数据库的应用程序?尝试关闭并重新打开它。
-
@DavidG 你说得对,它实际上进入了我们的阶段数据库,而不是我们的开发......将来有没有办法在添加列时指定你想要的数据库?
-
它使用与上下文相同的数据库。如果它进入您的暂存数据库,那是因为那是通过运行具有环境配置的应用程序连接到的数据库 - 参见例如docs.microsoft.com/en-us/aspnet/core/fundamentals/…