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,同步到数据库

  • 相关阅读:
    uni-app快速上手
    uni-app快速上手
    什么是uni-app?
    什么是uni-app?
    美颜小程序准备
    美颜小程序准备
    vue的基本使用
    vue的基本使用
    Web前端开发(高级)下册-目录
    Web前端开发(高级)下册-目录
  • 原文地址:https://www.cnblogs.com/intotf/p/12091909.html
Copyright © 2011-2022 走看看