且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用实体框架5将特定的ID插入到MySQL的自动递增字段中

更新时间:2023-09-23 23:30:22

解决方案我在插入之前找到了更改表的位置。这基本上是其他人给出的解决方案,但是我需要转一圈。

The solution I found where to alter the table before inserting into it. It's basicly the solution other people gave, however I needed to make a few turns.

这就是我所做的:

SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE Profile DROP PRIMARY KEY,
MODIFY _id INT PRIMARY KEY NOT NULL;

insert commmand here....

ALTER TABLE Profile DROP PRIMARY KEY,
MODIFY _id INT AUTO_INCREMENT PRIMARY KEY NOT NULL;

SET FOREIGN_KEY_CHECKS=1;