Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run migration in C#.NET project?

I have project that works with SQL server. In Models directory I have migrtions files like as one:

public partial class UserData : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.confirmation_code",
                c => new
                    {
                        sys_id = c.Long(nullable: false, identity: true),
                        resource_id = c.Guid(nullable: false),
                        code = c.String(maxLength: 64),
                        user_id = c.Long(nullable: false),
                        id = c.Guid(nullable: false),
                        edit_date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.sys_id)
                .ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
                .Index(t => t.user_id);
....

For development I use VisualStudio, how to run all migration to deploy?

like image 917
Darama Avatar asked Mar 08 '17 21:03

Darama


People also ask

How do you run migration?

Open the Package Manager Console from Tools → Library Package Manager → Package Manager Console and then run the enable-migrations command (make sure that the default project is the project where your context class is).

What is the command for migration?

There are four available main commands. Enable-Migrations: Enables Code First Migrations in a project. Add-Migration: Scaffolds a migration script for any pending model changes. Update-Database: Applies any pending migrations to the database.

How do I run EF migrations?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.

How do I create a database migration?

To create a migration, execute db-migrate create with a title. node-db-migrate will create a node module within ./migrations/ which contains the following two exports: exports. up = function (db, callback) { callback(); }; exports.


1 Answers

You should open the Nuget Management Console and type update-database command with migration name, and additional parameters if they are needed. Depending on your setup you might need to provide connection string name and/or project where they are located.

More on this: Entity Framework Code First Migrations.

like image 193
Paweł Łukasik Avatar answered Sep 29 '22 21:09

Paweł Łukasik