I have been trying to research this for a few hours, there is not a lot of good documentation and examples on this and I was hoping someone could provide some better understanding.
I have a database table that I am using Entity Framework Migrations on. The previous versions of this database utilized "INT32" as the primary keys for the table. We decided as a team that rather than trying to manage this for a large database, we would rather expand the amount of ID's we can hold to be a BIGINT.
I created a new migration and I am attempting to update the table to now hold the BIGINT value.
Here is the code I am utilizing to change this migration:
DropForeignKey("parts", "FK_Parts_Bins_BinID");
AlterColumn("bins", "ID", c => c.Long(nullable: false, identity: true));
AlterColumn("parts", "BinID", c => c.Long());
AddForeignKey("parts", "BinID", "bins", "ID", false, "FK_Parts_Bins_BinID");
I have a table noted as 'Parts' which holds a foreign key reference to the primary key 'ID' in the 'Bins' table. Before these were just ints, now I want to utilize BigINTs.
I believe I have 2 problems:
I cannot re-establish the connection between Bins and Parts because when I am creating the new 'identity' column the bins ID field is getting marked as 'unsigned' where my parts BinID column is not. So I get the following exception:
Referencing column 'BinID' and referenced column 'ID' in foreign key constraint 'FK_Parts_Bins_BinID' are incompatible.
I cannot figure out how to make my BinID column unsigned.
- I believe after I fix the above exception I may have an issue with the auto-increment field resetting back to 0 or 1. This would mean the existing data ID's would not be accounted for. Is there a best practice for updating the starting position to be the largest ID in the existing table?
Microsoft Documentation:
https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.migrations.builders.columnbuilder.long?view=entity-framework-6.2.0
question from:
https://stackoverflow.com/questions/65921785/entity-framework-columnbuilder 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…