Bug #71418 AddColumn with identity true doesn't work on .NET Connector 6.8.3
Description:
public partial class Migration2 : DbMigration
{
public override void Up()
{
RenameColumn(table: "DeviceUsage", name: "id", newName: "EquipmentuseID");
DropPrimaryKey("DeviceUsage", new[] { "id" });
AddColumn("DeviceUsage", "_id", c => c.Int(nullable: false, identity: true));
}
....
}
The above code works well with EF5 and .NET Connector 6.7.4; however with EF6 and Connector 6.8.3, an error "Incorrect table definition; there can be only one auto column and it must be defined as a key" was reported.
Different ways of handling the integer identity column are in MySqlMigrationCodeGenerator#Generate(ColumnModel op) of the two versions:
V6.7.4:
if (op.IsIdentity && type == "int")
{
sb.Append(" auto_increment primary key ");
}
V6.8.3:
if (op.IsIdentity && (new string[] { "tinyint", "smallint", "mediumint", "int", "bigint" }).Contains(type.ToLower()))
{
sb.Append(" auto_increment ");
autoIncrementCols.Add(op.Name);
}
V6.8.3 Adds the column to autoIncrementCols set, which is only handled in CreateTable statement, so AddColumn statment can't recognize the column as a primary key or key.
How to repeat:
1. Define an entity(Class: DeviceUsage) with a string property(Name: EquipmentuseID) mapped to primary key(Name: id) in database
Class DeviceUsage{
[Key("id")]
public string EquipmentuseID {get; set;}
public string OtherProperty {get; set;}
}
2. After the entity is mapped to a table, change the entity class defintion to
Class DeviceUsage{
[Key("_id")]
public int id {get; set;}
public string EquipmentuseID {get; set;}
public string OtherProperty {get; set;}
}
and construct the migration code as in the description
3. Apply the migration
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.048 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: public partial class Migration2 : DbMigration { public override void Up() { RenameColumn(table: "DeviceUsage", name: "id", newName: "EquipmentuseID"); DropPrimaryKey("DeviceUsage", new[] { "id" }); AddColumn("DeviceUsage", "_id", c => c.Int(nullable: false, identity: true)); } .... } The above code works well with EF5 and .NET Connector 6.7.4; however with EF6 and Connector 6.8.3, an error "Incorrect table definition; there can be only one auto column and it must be defined as a key" was reported. Different ways of handling the integer identity column are in MySqlMigrationCodeGenerator#Generate(ColumnModel op) of the two versions: V6.7.4: if (op.IsIdentity && type == "int") { sb.Append(" auto_increment primary key "); } V6.8.3: if (op.IsIdentity && (new string[] { "tinyint", "smallint", "mediumint", "int", "bigint" }).Contains(type.ToLower())) { sb.Append(" auto_increment "); autoIncrementCols.Add(op.Name); } V6.8.3 Adds the column to autoIncrementCols set, which is only handled in CreateTable statement, so AddColumn statment can't recognize the column as a primary key or key. How to repeat: 1. Define an entity(Class: DeviceUsage) with a string property(Name: EquipmentuseID) mapped to primary key(Name: id) in database Class DeviceUsage{ [Key("id")] public string EquipmentuseID {get; set;} public string OtherProperty {get; set;} } 2. After the entity is mapped to a table, change the entity class defintion to Class DeviceUsage{ [Key("_id")] public int id {get; set;} public string EquipmentuseID {get; set;} public string OtherProperty {get; set;} } and construct the migration code as in the description 3. Apply the migration