Can I rename the first code migration to ASP.NET MVC 5

This is a bit of a weird question about the first code migrations in asp.net mvc 5. I have a running project and I am using manual migrations to update my database. If I do anything that changes the structure of the database in my model, I then go to the Package Manager Console and click

add-migration "MigrationName"

but along the way, I named my two migrations with the wrong name. I would like to fix the name for each, but I want to make sure it doesn't affect their integrity. I am planning to rename the second part of the filename (descriptive part) and not the timestamp.

For the instance, I had the following name:

201411190809335_CreateStageTypeRender

but he had to read

201411190809335_CreateSeatingTypeRender

If I don't change the name in the future, I might be targeting this crash migration because I called it wrong.

It seems that when I renamed them before, in cases where it was not an important project, this visual studio renamed any subfiles (.cs, .resx). So it looks like it won't be a problem, plus the timestamp will stay in pace to keep them in order.

Questioner: Is there anything else I should take into account. Can I rename the descriptive part of the migration file name?

BTW .. I can also go into the Designer.cs file and rename the get return value from:

public sealed partial class CreateStageTypeRender : IMigrationMetadata
    private readonly ResourceManager Resources = new ResourceManager(typeof(CreateStageTypeRender));
    string IMigrationMetadata.Id
    {
        get { return "201411190809335_CreateStageTypeRender"; }
    }

      

to

public sealed partial class CreateSeatingTypeRender : IMigrationMetadata
    private readonly ResourceManager Resources = new ResourceManager(typeof(CreateSeatingTypeRender));
    string IMigrationMetadata.Id
    {
        get { return "201411190809335_CreateSeatingTypeRender"; }
    }

      

Finally, I went to the database and renamed the entries to match the old migration names and changed them to reflect the new migration names. Otherwise, my guess is that EF / Visual Studio will think there are new migrations when there are none.

I think all my bases are covered. Please let me know if you think I missed anything or if for some reason this is not a good idea.

+3


source to share


1 answer


I finally went back to the project that had this problem and it works great.

In your example, you indicate that you are changing the return type to CreateSeatingTypeRender ... I just want to clarify that for my testing in the name of consistency, there are five places to be done.

Four of them are in the code: the class name, the partial class name of the .designer file, the resource manager typeof, and the IMigrationMetadata.Id property you mentioned ...

Last place in the data, as you mentioned earlier, update the MigrationId, from the old name to the new one.



While making these changes, the update and database command worked great.

For those who have tried this, also remember, if you rename a migration in your dev database ... if this migration already exists on the production machine, you will have to manually rename the rows of the __migration table where, and in other places that this the migration has already been done when you deploy this machine.

Testing Notes: • I tested with ef 6.1.3 • This is not an MVC5 specification

0


source







All Articles