我在我的项目中使用mySQL数据库,并希望在列上创建索引。
我在用codefirst方法
这是我的迁徙
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”用于没有密钥长度的密钥规范
我怎么才能解决这个问题?
发布于 2020-11-06 08:40:51
这个问题与MySQL只能索引BLOB或TEXT列的第一个N个字符有关。
要解决此问题,请尝试从索引或唯一约束中移除文本或BLOB列,或将另一个字段设置为主键。此外,您还可以尝试使用VARCHAR类型并在其上设置长度限制(或尝试设置字符串MaxLength注释)。
https://stackoverflow.com/questions/64710567
复制相似问题