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?
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).
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With