微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Enable-Migrations已过时使用添加迁移开始使用迁移

如何解决Enable-Migrations已过时使用添加迁移开始使用迁移

好的,但是在配置过时之前我们使用的以下设置呢?

public Configuration()
{
    //AutomaticMigrationsEnabled = true; //it is Ok for Now as default value is true

    //what about the following settings??? 
    AutomaticMigrationDataLossAllowed = true; //Attention when using this!!!
    MigrationsDirectory = @"Migrations";
    ContextKey = "Demo.Domain.DemoDbContext";
}

在哪里可以设置这些设置?

解决方法

安装EntityFrameworkCore.Tools软件包,以便在Package Manager控制台中使用诸如Add-Migration和Update-Database之类的命令。您无需调用Enable-Migrations,并且附带说明AutomaticMigrationsEnabled已过时。

,

在PM控制台中,您始终可以使用以下命令运行--help命令: dotnet ef migrations add --help

然后您将能够看到所需的所有配置:

Usage: dotnet ef migrations add [arguments] [options]

Arguments:
  <NAME>  The name of the migration.

Options:
  -o|--output-dir <PATH>                 The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to "Migrations".
  --json                                 Show JSON output.
  -c|--context <DBCONTEXT>               The DbContext to use.
  -p|--project <PROJECT>                 The project to use.
  -s|--startup-project <PROJECT>         The startup project to use.
  --framework <FRAMEWORK>                The target framework.
  --configuration <CONFIGURATION>        The configuration to use.
  --runtime <RUNTIME_IDENTIFIER>         The runtime to use.
  --msbuildprojectextensionspath <PATH>  The MSBuild project extensions path. Defaults to "obj".
  --no-build                             Don't build the project. Only use this when the build is up-to-date.
  -h|--help                              Show help information
  -v|--verbose                           Show verbose output.
  --no-color                             Don't colorize output.
  --prefix-output                        Prefix output with level.

例如,如果您要将目录设置为“迁移”(默认设置):

dotnet ef migrations add MyMigration --output-dir Migrations

或在指定DbContext的同时添加迁移:

dotnet ef migrations add MyMigration --context MyDbContext

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。