mysql 创建索引失败,创建索引时,带有mysql数据库迁移的实体框架失败

what causes this error in MySQL with entity framework? I can generate the migration script and connect to the database but it doesn't like the SQL generated particularly "hash" when trying to create indexes.

Example:

CREATE index `IX_Facility_ID` on `Contact.Address` (`Facility_ID` DESC) using HASH

Error:

MySql.Data.MySqlClient.MySqlException (0x80004005): Incorrect usage of spatial/fulltext/hash index and explicit index order

Is there any way around this? This is with EF 6 and the latest mysql dlls.

解决方案

i haved the same problem, after i read on posts, i decided create a class inherits ofMySqlMigrationSqlGenerator and override protected override MigrationStatement Generate ( CreateIndexOperation op ), then on configuration of migration i add : SetSqlGenerator ( "MySql.Data.MySqlClient", new myMigrationSQLGenerator ( ) );

this is the code of class:

public class myMigrationSQLGenerator : MySqlMigrationSqlGenerator

{

private string TrimSchemaPrefix ( string table )

{

if ( table.StartsWith ( "dbo." ) )

return table.Replace ( "dbo.", "" );

return table;

}

protected override MigrationStatement Generate ( CreateIndexOperation op )

{

var u = new MigrationStatement ( );

string unique = ( op.IsUnique ? "UNIQUE" : "" ), columns = "";

foreach ( var col in op.Columns )

{

columns += ( $"`{col}` DESC{( op.Columns.IndexOf ( col ) < op.Columns.Count - 1 ? ", " : "" )}" );

}

u.Sql = $"CREATE {unique} INDEX `{op.Name}` ON `{TrimSchemaPrefix ( op.Table )}` ({columns}) USING BTREE";

return u;

}

}

and this is the code on Migrations\Configuration.cs:

public Configuration ()

{

AutomaticMigrationsEnabled = false;

SetSqlGenerator ( "MySql.Data.MySqlClient", new myMigrationSQLGenerator ( ) );

}

this work for me.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值