【发布时间】:2021-02-18 22:45:00
【问题描述】:
我的项目使用 mySQL 数据库,并希望在列上创建索引。
我正在使用代码优先方法
这是我的迁移
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_RecruitmentAgencies_AbpTenants_TenantId",
table: "RecruitmentAgencies");
migrationBuilder.DropIndex(
name: "IX_RecruitmentAgencies_TenantId",
table: "RecruitmentAgencies");
migrationBuilder.AddColumn<string>(
name: "ContactEmail",
table: "RecruitmentAgencies",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_RecruitmentAgencies_ContactEmail",
table: "RecruitmentAgencies",
column: "ContactEmail");
}
当我尝试应用它时,我得到了这个错误
在没有密钥长度的密钥规范中使用了 BLOB/TEXT 列“ContactEmail”
我该如何解决这个问题?
【问题讨论】:
-
为什么在你的程序中这样做?索引是一次性的。直接在数据库中做
-
我先用代码,所以我需要这个方法的答案@juergend
-
您只能对
TEXT类型的列进行部分索引。这是 MySQL 的限制。你需要弄清楚如何表达。 -
您真的需要 TEXT 数据类型(64 KB)作为联系电子邮件吗?也许 VARCHAR(255) 就足够了吗?
标签: c# mysql sql asp.net asp.net-core