Resolved: Entity Framework .net 5 core rename to table column | alter rename column in .net core EF.

The issue was supposed we have one User table and it has some columns like Id, FirstName, Surname, PhoneNumber, or Email.

database table and its fields.

There we wanted to Rename Surname to LastName.

The problem occurs when we will run migration after the above Change. It will not make rename or alter to the column, It will Drop to Surname and Add a new column LastName. So it’s totally wrong in this case we will lose our column data.

In this model we just rename to it and run migration.
There you can see when we will run this migration it will remove to Surname and Add New column LastName So we will lose our Field or its data.

So what to Do there. Follow these steps.

Step 1.

So in first step we need to remove Red block part. And Add new Rename Column part and change old name to newName.

Step 2. Just look your data in database with old field.

Step 3. Just run your migration. update-database

Step 4. Just look your database again. Without lost our data we achive it.