0

I am trying to update my database after a migration but I am getting an error saying "There is already an object named [TableName] in the database."

below is how my project is structured

AtlasBooking.Client houses the startup.cs file and is contained in a different namespace while AtlasBooking.Storing is where I house pretty much everything else about database interaction

 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 references AtlasBooking.Storing.csproj as shown below

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

I was successfully added the migration with the following

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

to update database I used this

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

I've also tried

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

and I get the error Unrecognized option '--force'

how do I fix this?

user8964654
  • 87
  • 1
  • 9
  • 1
    Does this answer your question? [Update-Database command is not working in ASP.Net Core / Entity Framework Core because object in database already exists](https://stackoverflow.com/questions/43687433/update-database-command-is-not-working-in-asp-net-core-entity-framework-core-b) – devNull Dec 31 '19 at 18:24

1 Answers1

-1

you should use a double dash --force or -f for short hand.

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

Update

Nevermind, you can't force a database update. Your database must be out of sync with your migrations. If you don't have production data in the database, the easiest option would be to delete it and reapply your migrations.

Todd Skelton
  • 6,839
  • 3
  • 36
  • 48