C# 启用迁移已过时。使用“添加迁移”开始使用迁移

C# 启用迁移已过时。使用“添加迁移”开始使用迁移,c#,asp.net-mvc,entity-framework,asp.net-core,entity-framework-core,C#,Asp.net Mvc,Entity Framework,Asp.net Core,Entity Framework Core,好的,但是在配置被禁用之前我们使用的以下设置呢 public Configuration() { //AutomaticMigrationsEnabled = true; //it is Ok for now as default value is true //what about the following settings??? AutomaticMigrationDataLossAllowed = true; //Attention when using th

好的,但是在配置被禁用之前我们使用的以下设置呢

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";
}

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

在package Manager控制台中安装EntityFrameworkCore.Tools软件包,以使用添加迁移和更新数据库等命令。您不需要调用Enable Migrations,顺便说一句,AutomaticMigrationsEnabled已过时。

安装EntityFrameworkCore.Tools软件包,用于在package Manager控制台中使用添加迁移和更新数据库等命令。您不需要调用Enable Migrations,顺便说一句,AutomaticMigrationsEnabled已过时。

在PM控制台中,您始终可以使用以下命令运行-help命令: dotnet ef迁移添加-帮助

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

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.
或在指定DbContext时添加迁移:

dotnet ef migrations add MyMigration --context MyDbContext

在PM控制台中,您始终可以使用以下命令运行-help命令: dotnet ef迁移添加-帮助

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

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.
或在指定DbContext时添加迁移:

dotnet ef migrations add MyMigration --context MyDbContext


您可以将数据库迁移与软件包管理器控制台一起使用,使用诸如“添加迁移初始值”和“然后更新数据库”等命令。@SalahAkbari我试图执行EntityFrameworkCore\enable migrations-ContextTypeName Demo.ApplicationDbContext-MigrationsDirectory:migrations\Application,但是遇到了obsolote错误。您不需要启用它,正如我所说的,我已经在package manager控制台中执行了我的命令。但是我也不能使用我以前使用的任何迁移命令thta。这些新命令的完整配置在哪里?我建议您在这里花些时间-您可以使用package manager控制台进行数据库迁移,使用“添加迁移初始值”和“然后更新数据库”等命令。@SalahAkbari我试图执行EntityFrameworkCore\enable migrations-ContextTypeName Demo.ApplicationDbContext-MigrationDirectory:migrations\Application,但遇到了obsolote错误。您不需要启用它,正如我所说,我已经在PackageManager控制台中执行了我的命令,但我也不能使用我以前使用的任何迁移命令。这些新命令的完整配置在哪里?我真的建议您在这里花些时间-谢谢您的回复。首先,我定位到迁移文件所在的项目。然后我尝试在cmd和VS代码终端上执行这个命令,因为找不到指定的命令或文件,所以无法执行。错误有什么想法吗?通常我使用cmd来执行dotnet命令。我以前也安装过EntityFrameworkCore.Tools包。这是另一个问题,键入dotnet-info时会得到什么?我看到.NET Core SDK反映了任何global.json:Version:3.1.402。。。。消息和列出的许多内容没有任何错误。那么,我可以使用cmd作为dotnetcli吗?我想我可以使用cmd或类似的cmder作为任何库的CLI,只要能够正确地将它们的路径添加到环境变量中。这是真的吗?是的,这是真的,但您必须在迁移目录中谢谢您的回复。首先,我定位到迁移文件所在的项目。然后我尝试在cmd和VS代码终端上执行这个命令,因为找不到指定的命令或文件,所以无法执行。错误有什么想法吗?通常我使用cmd来执行dotnet命令。我以前也安装过EntityFrameworkCore.Tools包。这是另一个问题,键入dotnet-info时会得到什么?我看到.NET Core SDK反映了任何global.json:Version:3.1.402。。。。消息和列出的许多内容没有任何错误。那么,我可以使用cmd作为dotnetcli吗?我想我可以使用cmd或类似的cmder作为任何库的CLI,只要能够正确地将它们的路径添加到环境变量中。这是真的吗?是的,这是真的,但您必须在迁移目录中