时间:2021-07-01 10:21:17 帮助过:55人阅读
public class ReservationMigrationsDbContext : AbpDbContext<ReservationMigrationsDbContext> { public ReservationMigrationsDbContext( DbContextOptions<ReservationMigrationsDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.ConfigureReservation(); } }
创建数据库迁移上下文工厂
public class ReservationMigrationsDbContextFactory : IDesignTimeDbContextFactory<ReservationMigrationsDbContext> { public ReservationMigrationsDbContext CreateDbContext(string[] args) { var configuration = BuildConfiguration(); var builder = new DbContextOptionsBuilder<ReservationMigrationsDbContext>() .UseOracle(configuration.GetConnectionString("NmReservation")); return new ReservationMigrationsDbContext(builder.Options); } private static IConfigurationRoot BuildConfiguration() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false); return builder.Build(); } }
注意启动项目中配置的数据库连接字符串的名字要和GetConnectionString方法中的名字一致,也就是NmReservation。
在配置文件appsettings.json中配置如下:
在数据中响应用户,并赋予权限。
在工具>NuGet包管理器>程序包管理器控制台,选择默认项目为上面创建的数据库迁移项目。
执行add-migration:
提示:Your startup project ‘Nm.Reservation.Api‘ doesn‘t reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
解决办法:启动项目中安装Microsoft.EntityFrameworkCore.Design包。
执行add-migration:
提示:Could not load assembly ‘Nm.Reservation.Migrations‘. Ensure it is referenced by the startup project ‘Nm.Reservation.Api‘.
解决办法:在启动项目中引用Nm.Reservation.Migrations。
执行add-migration:
提示:
Build started...
Build succeeded.
To undo this action, use Remove-Migration.
提示如上信息则数据库迁移创建成功。
执行update-database:
提示:ORA-00972,检查字段名、主键、外键、索引名是否标识符过长,数据库字段长度在oracle中不能超过30个字符,其他名称不能超过50个字符。
创建数据库迁移完毕。
创建数据库迁移
标签:ack var 安装 on() over bpm 依次 creating image