簡體   English   中英

使用 CLI 命令更新 dbcontext

[英]updating a dbcontext using the CLI commands

我正在嘗試在遷移后更新我的數據庫,但收到一條錯誤消息,提示“數據庫中已經有一個名為 [TableName] 的對象”。

下面是我的項目的結構

AtlasBooking.Client 存放startup.cs文件並包含在不同的命名空間中,而 AtlasBooking.Storing 是我存放與數據庫交互幾乎所有其他內容的地方

 1.AtlasBooking.Client
    -View folder
    -ViewModels folder
    -Controller folder
    -Program.cs file
    -Startup.cs file
    -AtlasBooking.Client.csproj file

2. AtlasBooking.Storing
     -DbContext folder
     -Repositories folder
     -Migrations folder
     -AtlasBooking.Storing.csproj file

AtlasBooking.Client.csproj 引用 AtlasBooking.Storing.csproj 如下圖

<ItemGroup>
    <ProjectReference Include="..\AtlasBooking.Storing\AtlasBooking.Storing.csproj" />
  </ItemGroup>

我成功地添加了以下遷移

AtlasBooking.Storing: dotnet ef --startup-project ../AtlasBooking.Client/AtlasBooking.Client.csproj migrations add initialCreate --context AtlasBookingDbContext -o Migrations

更新數據庫我用這個

AtlasBooking.Storing:  dotnet ef --startup-project ../AtlasBooking.Client/AtlasBooking.Client.csproj  database update

我也試過

AtlasBooking.Storing:  dotnet ef --startup-project ../AtlasBooking.Client/AtlasBooking.Client.csproj  database update --force

我收到錯誤Unrecognized option '--force'

我該如何解決?

您應該使用雙破折號--force-f來表示簡寫。

https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-database-update

更新

沒關系,你不能強制更新數據庫。 您的數據庫必須與您的遷移不同步。 如果數據庫中沒有生產數據,最簡單的選擇是刪除它並重新應用遷移。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM