简体   繁体   English

Entity Framework Core - 自定义迁移停止工作

[英]Entity Framework Core - Custom Migration stopped working

For a while now I've had a custom migration in my Entity Framework Core project that creates some SQL objects - stored procedures and functions.一段时间以来,我在我的 Entity Framework Core 项目中进行了自定义迁移,该项目创建了一些 SQL 对象 - 存储过程和函数。

It looks something like this:它看起来像这样:

using Microsoft.EntityFrameworkCore.Migrations;

namespace CaseFlow_API.Migrations
{
    public partial class AdditionalSQLObjects : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // Functions
            var f_exampleFunction = @"CREATE OR REPLACE FUNCTION public.f_exampleFunction(
    character varying,
    character varying,
    character varying,
    integer)
/*
SOME SQL CODE
*/
";

            migrationBuilder.Sql(f_exampleFunction);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
        }
    }
}

However now it stopped working - functions and procedures are not created when updating the db.但是现在它停止工作 - 更新数据库时不会创建函数和过程。 I don't think I changed anything in how migrations are created.我不认为我改变了迁移的创建方式。 What I would do usually is that I'd run我通常会做的是我会跑

dotnet ef migrations add Initial
dotnet ef database update

I tried dropping all migrations, dropping the database, recreating the AdditionalSQLObjects.cs class.我尝试删除所有迁移,删除数据库,重新创建AdditionalSQLObjects.cs class。 I have no idea how to debug/fix this.我不知道如何调试/修复这个。

Can you please point me to places where I can fix this?你能指出我可以解决这个问题的地方吗?

Ok, so the custom migration finally works.好的,所以自定义迁移终于起作用了。 Here's what I did (added class attributes):这是我所做的(添加了 class 属性):

[DbContext(typeof(CaseflowingContext))]
[Migration("CustomMigration_AdditionalSQLObjects")]
public partial class AdditionalSQLObjects : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
        {
          //miration code
        }
}

I have no idea what happened, because this migration used to work without the attributes, but I'll take it.我不知道发生了什么,因为这种迁移过去常常在没有属性的情况下工作,但我会接受它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM