zoukankan      html  css  js  c++  java
  • .net core 3.1 ef Migrations 使用 CLI 数据迁移及同步

    本文为 CLI 方式执行数据结构同步及迁移,请确定当前电脑是否安装 .net core 运行环境

    4.1. 打开 cmd ,执行:dotnet tool install --global dotnet-ef 如版本过低请输入:dotnet tool install --global dotnet-ef

    4.2. 安装最新的 .NET Core SDK 3.0

    https://dotnet.microsoft.com/download/dotnet-core/3.1

    4.3. cd D:work项目文件夹 (进入到项目的目录),安装 EF Design dotnet add package Microsoft.EntityFrameworkCore.Design

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
          <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>
    

    4.4. 验证工具是否已经安装好

        dotnet restore
        dotnet ef
    
                         _/\__
                   ---==/    \
             ___  ___   |.    |
            | __|| __|  |  )   \
            | _| | _|   \_/ |  //|\
            |___||_|       /   \/\
    
    Entity Framework Core .NET Command-line Tools 3.1.0
    

    4.5. 第一次执行(新增迁移任务)

    dotnet ef migrations add initial

    Build started... Build succeeded. Done. To undo this action, use 'ef migrations remove'

    4.6. 有模型变化时,执行变更任务 dotnet ef migrations add testTable

    然后运行项目就可以自动同步数据结构. 数据初始化见 MigrateHostedService.cs, 也可以执行 dotnet ef database update,同步到数据库

  • 相关阅读:
    Js 之获取QueryString的几种方法
    Go语言 之md5加密
    跨域取文件(跨项目)
    System.IO
    System.Threading.Tasks
    JS存取Cookies值,附自己写的获取cookies的一个方法
    HttpServerUtility 和 HttpUyility
    JS格式化时间
    JS获取页面传过来的值
    Navigator 对象
  • 原文地址:https://www.cnblogs.com/intotf/p/12091909.html
Copyright © 2011-2022 走看看