Pac*_*man 2 mysql entity-framework ef-migrations
我已经设置了实体框架来使用MySQL并创建了一个迁移.
当我运行update-database时,我得到错误"table dbname.dbo.tablename"不存在.在-Verbose模式下运行我看到导致错误的语句:
alter table `dbo.Comments` drop foreign key `FK_dbo.Comments_dbo.Comments_Comment_ID`
Run Code Online (Sandbox Code Playgroud)
当我在MySQL工作台中直接运行查询时会抛出相同的错误.
问题似乎是dbo.迁移集中的前缀.表单dbo.tablename中的任何内容都不会运行,表示该表不存在.例如select*from dbo.tablename失败但select*from tablename有效.数据库由Entity Framework生成,代码首次迁移也由EF生成.
但是,迁移会使用dbo生成所有内容.前缀,不起作用.
有人有解决方案吗?
小智 13
我今天也遇到了这个问题; 在这里找到我的答案: MySqlMigrationCodeGenerator
你必须设置:
CodeGenerator = new MySqlMigrationCodeGenerator();
Run Code Online (Sandbox Code Playgroud)
在您的上下文的配置类中.这将摆脱MySQL的架构乱码.我的Configuration类看起来像这样:
internal sealed class Configuration : DbMigrationsConfiguration<YourContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator("MySql.Data.MySqlClient", new MySqlMigrationSqlGenerator());
SetHistoryContextFactory("MySql.Data.MySqlClient", (conn, schema) => new MySqlHistoryContext(conn, schema));
CodeGenerator = new MySqlMigrationCodeGenerator();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5699 次 |
| 最近记录: |