Ben Donnelly
Ben Donnelly

Reputation: 1261

Entityframework Core Migrations

I have a .net core 2 project, along with Entity framework Core.

I have an existing database, and I've mapped them out to database entities in code.

The problem is that when I add a migration, expectedly it picks up my entity as a new table, however it is an existing table. The table shares the same name.

I suppose, I could just remove the contents of the Up method of the migration, but I want to know if there is a proper way instead of a workaround.

So, what I am asking is how can I tell entity framework core that this table is already existing?

Upvotes: 0

Views: 145

Answers (1)

Steve Greene
Steve Greene

Reputation: 12304

EF 6 had an -IgnoreChanges option that would just take a snapshot with no Up() code, but that feature is not in EF Core (yet). See here.

If you comment out the Up() code as you have suggested that will indeed capture a snapshot of your existing objects and subsequent migrations will be incremental.

Upvotes: 2

Related Questions