New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use new created columns in SQL - Statement in Up() Migration [DNET811] #746
Comments
Commented by: @cincuranet It's probably because of transactions. Can you script this migration and paste it here? |
Modified by: @cincuranetstatus: Open [ 1 ] => In Progress [ 3 ] |
Commented by: Andreas Patock (apatock) Do you mean this? ALTER TABLE "Device" DROP CONSTRAINT "FK_ManDevManId" The Error is: Dynamic SQL Error |
Commented by: @cincuranet For not null columns the default value is generated (even if you haven't specified it), see "ALTER TABLE "Device" ADD "DeviceTypeId" INT DEFAULT 0 NOT NULL ". The whole migration is executed in a transaction, the update doesn't see yet the table, because of how DDL and DML inside same transaction work in Firebird. Not sure provider can do much here. I think the best bet is to split this to two migrations. |
Submitted by: Andreas Patock (apatock)
Votes: 1
If I have the following migration:
public partial class AddDeviceType : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.DeviceType",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(nullable: false, maxLength: 128),
ManufacturerId = c.Int(nullable: false),
})
.PrimaryKey(t => http://t.Id)
.ForeignKey("dbo.Manufacturer", t => t.ManufacturerId, cascadeDelete: true)
.Index(t => t.ManufacturerId);
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.
The text was updated successfully, but these errors were encountered: