I have two columns in a table which I created them using code first approach then I changed their data types in the C# model not the actual database and last I tried the later migration in order to change their data type in the database
public partial class PriceAndMargin : DbMigration
{
public override void Up()
{
AddColumn("dbo.Items", "Price", c => c.Int(nullable: false));
AddColumn("dbo.Items", "ShortageMargin", c => c.Int(nullable: false));
}
public override void Down()
{
DropColumn("dbo.Items", "ShortageMargin");
DropColumn("dbo.Items", "Price");
}
}
If I got it write this code should drop the Price column and the ShortageMargin column and recreates them but instead it displays this message in the console for me
Column names in each table must be unique. Column name 'Price' in table 'dbo.Items' is specified more than once
thanks in advance
If I got it write this code should drop the Price column and the ShortageMargin column and recreates them
Not really, your "up" adds the columns. The "down" section is only if you want to "downgrade" your database (ou revert the migration). I don't know how you changed the type of your object, and from which version you ran the 'add-migration' command but you should have a script with " AlterColumn instead of AddColumn
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.