Can't use new created columns in SQL - Statement in Up() Migration

                 Key: DNET-811
             Project: .NET Data provider
          Issue Type: Bug
          Components: Entity Framework
    Affects Versions:
            Reporter: Andreas Patock
            Assignee: Jiri Cincura

If I have the following migration:

   public partial class AddDeviceType : DbMigration
        public override void Up()
                c => new
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 128),
                        ManufacturerId = c.Int(nullable: false),
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Manufacturer", t => t.ManufacturerId, 
cascadeDelete: true)
                .Index(t => t.ManufacturerId);
            AddColumn("dbo.Device", "TempDeviceTypeId", c => c.Int());
            AddColumn("dbo.Device", "DeviceTypeId", c => c.Int(nullable: 
            CreateIndex("dbo.Device", "DeviceTypeId");
            AddForeignKey("dbo.Device", "DeviceTypeId", "dbo.DeviceType", "Id", 
cascadeDelete: true);

            Sql("UPDATE \"Device\" d SET d.\"DeviceTypeId\" = (SELECT t.\"Id\" 
from \"DeviceType\" t where t.\"ManufacturerId\" = d.\"ManufacturerId\" ORDER 
BY t.\"Id\" ROWS 1)");

I can a Column unknown "DeviceTypeId" exception when running the migration. 
This can found on many examples in the internet and is working with mssql.

I had the idea to do this in two migrations, but the "DeviceTypeId" is a not 
null field and so the first migration throws an exception also.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


Check out the vibrant tech community on one of the world's most
engaging tech sites,!
Firebird-net-provider mailing list

Reply via email to