EF migration problem RRS feed

  • Question

  • User1700527076 posted


    I'm trying to add a column and then run some simple sql on the new column.

    Here is the migration class:

    public partial class PortalId : Migration
            protected override void Up(MigrationBuilder migrationBuilder)
                    name: "PortalId",
                    table: "School",
                    isNullable: true);
                migrationBuilder.Sql("UPDATE School SET PortalId = SchoolId");
            protected override void Down(MigrationBuilder migrationBuilder)
                migrationBuilder.DropColumn(name: "PortalId", table: "School");

    But when I try to update the database with this migration step I get this exception: 
    System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'PortalId'.

    Any ideas?

    Tuesday, October 6, 2015 1:54 PM


  • User1700527076 posted

    Solved it temporarily by moving the sql part into another migration step afterwards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 6, 2015 3:33 PM