Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-create initial migration on the same .cs file

As common in EF Code First I've generated an "Initial Create" migration file where is located an outdated model of my db (I'm developing the app so the model is still changing). Now I have a "new model" defined in my code and instead of creating a new migration for that I just want to update the already existing file, because it still is the initial create migration.

I've tried using this without any luck

Update-database -targetmigration $initialcreate

It returns

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
You can use the Add-Migration command to write the pending model changes to a code-based migration.

I also tried this one, but it's always creating a new .cs file

Add-Migration InitialCreate

I'll appreaciate your help

like image 940
Anon Dev Avatar asked Jun 08 '16 04:06

Anon Dev


People also ask

How do I code my first migration to an existing database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.


1 Answers

Just delete the initial migration files from the 'Migrations' folder and retry.

like image 105
snnpro Avatar answered Oct 17 '22 08:10

snnpro