-1

With my recent changes on one branch, let's name it Branch A, I changed relations between entities, as well as renamed some properties. I created migrations and applied them to our Postgres-Database, good so far. I committed and pushed the migrations to the git repo and created a pull request. Now I'm waiting on the review of a colleague of mine to merge it to the master branch.

Now the problem.

I started to work on the next item and created another branch, Branch B. I created it from the master, so Branch B does NOT have the changes I made with Branch A, but the Database does, as we don't have it into source control. Now I get, of course, errors, as it cannot find the data with the renamed property from Branch A and the not yet renamed property of Branch B. I could drop the database and recreate it with the initial migration, but that's a lot of work and I will lose data.

We're working with .NET 5 and EF Core, the database provider is Postgres.

So, how do I resolve this misery, without having the database added to the source control?

Nico
  • 1
  • 1
  • 3

1 Answers1

0

You can try to apply previous migration (from the master) to your already updated database. It'll try to reverse the changes. Check the link below:

https://stackoverflow.com/a/38197891/4777147

Posio
  • 962
  • 4
  • 15
  • All I get when I try to apply the previous migration is `No migrations were applied. The database is already up to date`. And wiping the database does also not work. – Nico Apr 28 '22 at 07:27
  • You probably try just to apply migrations... In the case, when you want to apply previous migration you have to specify it's name EXPLICITLY `dotnet ef database update `. – Posio Apr 28 '22 at 07:49
  • The previous migration is on master the latest migration. The master does not know that there is one more migration applied to the database. But I could try to switch to the branch where I created the migration and update there to the previous migration. – Nico Apr 28 '22 at 08:02
  • You should "rollback" the migration BEFORE you switch to the master. After switch to the master, the migration you just rolled-back to, should be the latest one. – Posio Apr 28 '22 at 08:08
  • I just fixed it by switching to the branch where I created the new migration, updated the previous migration to the database, and then switched back to my current branch. Everything else I tried resulted in an error or it did nothing. – Nico Apr 28 '22 at 08:11
  • That's exactly what I suggested you to do .. – Posio Apr 28 '22 at 10:10