简体   繁体   中英

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?

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. You don't need to call Enable-Migrations, and as a side note AutomaticMigrationsEnabled is obsolete.

In the PM Console you can always run the --help command with: 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):

dotnet ef migrations add MyMigration --output-dir Migrations

Or add a migration while specifying the DbContext:

dotnet ef migrations add MyMigration --context MyDbContext

Enable-Migrations was for the older version. new version support to the Add-migration
first enter add-migration "setupName" .
setup name is a any recognizable name eg: add migration "initialSetup"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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