繁体   English   中英

启用迁移已过时。 使用 Add-Migration 开始使用 Migrations

[英]Enable-Migrations is obsolete. Use Add-Migration to start using Migrations

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

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包,以便在包管理器控制台中使用 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.

例如,如果要将目录设置为 Migrations(这是默认设置):

dotnet ef migrations add MyMigration --output-dir Migrations

或者在指定 DbContext 时添加迁移:

dotnet ef migrations add MyMigration --context MyDbContext

Enable-Migrations 适用于旧版本。 添加迁移的新版本支持
首先输入 add-migration "setupName" 。
设置名称是任何可识别的名称,例如:添加迁移“initialSetup”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM