Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually add a migration?

I've been using Entity framework code first in a project and all the tables have been created /modified a while ago. Now I need to add an unique constraint to a table. I want to create a migration which will have the following row in the Up() method. And there is no change on the model classes.

CreateIndex("TableName", new[] { "Column1" }, true, "IX_UniqueKey");

And maybe the following row in the Down()

DropIndex("TableName", new [] { "Column1" });

Can I just manually create a file under the folder Migrations? And is there any mandatory file name convention?

How to create the .Designer.cs and .resx files? Or should I use add-migration with some parameters?

like image 328
ca9163d9 Avatar asked Mar 17 '14 05:03

ca9163d9


People also ask

How do I add a new migration?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.


1 Answers

Using add-migration is the way for this. Just use add-migration yourMigrationName and it will automatically create all the files you need.

Then you just alter the Up() and Down() methods with the values that you need

like image 99
Thewads Avatar answered Oct 28 '22 11:10

Thewads