如何在 MySQL 中使用 Fluent Migrator 自动生成 UUID/GUID?

Pte*_*oid 5 mysql uuid guid fluent-migrator asp.net-core

我正在尝试将默认值 NewGuid() 设置为 MySQL 5.7 中的 UUID/GUID 列(在 .Net Core 中使用 FluentMigrator)。

Create.Table("table")
.WithColumn("auto_guid").AsGuid().NotNullable().WithDefaultValue(SystemMethods.NewGuid)
Run Code Online (Sandbox Code Playgroud)

根据 Fluent Migrator文档,应该支持 NewGuid,但出现错误:

“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以获取在附近使用的正确语法……”

我搜索了任何类似的问题和解决方案,但找不到任何。

使用 Fluent Migrator 是否可以在 MySQL 中自动生成 UUID/GUID?

Mar*_* D. 4

您使用了错误的方法。使用.WithDefault(SystemMethods.NewGuid)而不是.WithDefaultValue().