Pomelo.EntityFramework.Mysql这个驱动在迁移和很多方面比oracle公司发布的mysql ef core驱动好很多,推荐使用。
如果dotnet ef 命令提示
无法执行,因为找不到指定的命令或文档。
可能的原因包括:
*你拼错了内置的 dotnet 命令。
*你打算执行 .NET Core 进程,但 dotnet-ef 不存在。
*你打算运行全局工具,但在路径上找不到名称前缀为 dotnet 的可执行文档。
解决
dotnet tool install --global dotnet-ef --version 3.0.0-*
要加上这个NuGet包否则dot net ef xxx的指令会报错:
Microsoft.EntityFrameworkCore.Tools
另外两个需要的NuGet包是:
Pomelo.EntityFrameworkCore.MySql Pomelo.EntityFrameworkCore.MySql.Design
然后在程序包管理器控制台把默认项目设置成Model项目 Context类里加上配置:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseMySql("Server=localhost;Port=3306;Database=xxx; User=xxx;Password=xxx;"); } }
运行dotnet ef migrations add DATA_MODEL_NAME
就可以创建可迁移数据模型了
其他常用指令:
1.增加迁移 dotnet ef migrations add 名字
2.删除迁移 dotnet ef migrations remove
3.更新数据库 dotnet ef database update
4.生成脚本 dotnet ef migrations script
5.还原数据库版本 dotnet ef database update 名字
点击数:152
能在代码中完成数据迁移不?还是只能通过控制台?
你可以启动一个控制台进程做这个操作啊