【发布时间】:2021-01-27 20:46:57
【问题描述】:
如何将自动增量 int 的数据类型更改为 GUID?
我正在尝试更改我的 pk 定义的数据类型,如下所示:
[Id] INT IDENTITY (1, 1) NOT NULL
...到向导。
在我的模型中,我只是更改了数据类型
然后我运行了这两个命令:
add-migration myIntToGuid
update-database
运行update-database后,我得到了这个:
PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [202101272031026_changeIdToGuid].
Applying explicit migration: 202101272031026_changeIdToGuid.
System.Data.SqlClient.SqlException (0x80131904): Identity column 'Id' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, unencrypted, and constrained to be nonnullable.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
如何将自动增量 int 的数据类型更改为 GUID?
【问题讨论】:
-
为什么不添加详细并共享sql?
-
另外,底层数据库是什么?
-
那么这个 202101272031026_changeIdToGuid 脚本是什么样子的?
-
你看过这个帖子是否有可能的答案stackoverflow.com/questions/36022901/…
标签: c# .net entity-framework entity-framework-6