[英]Enable-Migrations is obsolete. Use Add-Migration to start using Migrations
Ok, but what about the following settings that we were using before the Configuration is obsolate?好的,但是我们在 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";
}
Where can I set these settings?我在哪里可以设置这些设置?
Install EntityFrameworkCore.Tools
package for using commands like Add-Migration and Update-Database in Package Manager Console.安装EntityFrameworkCore.Tools
包,以便在包管理器控制台中使用 Add-Migration 和 Update-Database 等命令。 You don't need to call Enable-Migrations, and as a side note AutomaticMigrationsEnabled
is obsolete.您不需要调用 Enable-Migrations,作为旁注, AutomaticMigrationsEnabled
已过时。
In the PM Console you can always run the --help
command with: dotnet ef migrations add --help
.在 PM 控制台中,您始终可以使用以下命令运行--help
命令: dotnet ef migrations add --help
。
Then you will be able to see all the configuration needed:然后您将能够看到所需的所有配置:
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.
For example if you want to set the directory to Migrations (it is the default):例如,如果要将目录设置为 Migrations(这是默认设置):
dotnet ef migrations add MyMigration --output-dir Migrations
Or add a migration while specifying the DbContext:或者在指定 DbContext 时添加迁移:
dotnet ef migrations add MyMigration --context MyDbContext
Enable-Migrations was for the older version. Enable-Migrations 适用于旧版本。 new version support to the Add-migration添加迁移的新版本支持
first enter add-migration "setupName" .首先输入 add-migration "setupName" 。
setup name is a any recognizable name eg: add migration "initialSetup"设置名称是任何可识别的名称,例如:添加迁移“initialSetup”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.