Forum Discussion

narensrinivas's avatar
narensrinivas
Copper Contributor
Oct 08, 2024

Can We add migration file from c#, instead of PackageManagerConsole

Hi,

is there any possibilities to add migration file from c# in core project, entity framework code first project. I can able to add the migration file from PackageManagerConsole, but could not able to add from c#

1 Reply

  • Hi narensrinivas  Yes there is way you can add migration manually 

     

    Here is the steps : 

     

    • Create a Migration Class: You can manually create a migration class that inherits from Migration and implement the Up and Down methods.

    • Add the Migration to the Context: You would then need to add the migration to your DbContext.

    • Apply the Migration: You can use the Database.Migrate() method to apply the migration to your database.

     

Resources