Table of Contents

Class Migration

Namespace
Microsoft.EntityFrameworkCore.Migrations
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

A base class inherited by each EF Core migration.

public abstract class Migration
Inheritance
Migration
Inherited Members
Extension Methods

Remarks

See Database migrations for more information and examples.

Constructors

Migration()

protected Migration()

Fields

InitialDatabase

The migration identifier for the empty database.

public const string InitialDatabase = "0"

Field Value

string

Properties

ActiveProvider

The name of the current database provider.

public virtual string? ActiveProvider { get; set; }

Property Value

string

Remarks

This can be used to write conditional code in the migration such that different changes can be made to the database depending on the type of database being used.

See Database migrations for more information and examples.

DownOperations

The MigrationOperations that will migrate the database 'down'.

public virtual IReadOnlyList<MigrationOperation> DownOperations { get; }

Property Value

IReadOnlyList<MigrationOperation>

Remarks

That is, those operations that need to be applied to the database to take it from the state left in by this migration so that it returns to the state that it was in before this migration was applied.

See Database migrations for more information and examples.

TargetModel

The Microsoft.EntityFrameworkCore.Metadata.IModel that the database will map to after the migration has been applied.

public virtual IModel TargetModel { get; }

Property Value

IModel

Remarks

See Database migrations for more information and examples.

UpOperations

The MigrationOperations that will migrate the database 'up'.

public virtual IReadOnlyList<MigrationOperation> UpOperations { get; }

Property Value

IReadOnlyList<MigrationOperation>

Remarks

That is, those operations that need to be applied to the database to take it from the state left in by the previous migration so that it is up-to-date with regard to this migration.

See Database migrations for more information and examples.

Methods

BuildTargetModel(ModelBuilder)

Implemented to build the TargetModel.

protected virtual void BuildTargetModel(ModelBuilder modelBuilder)

Parameters

modelBuilder ModelBuilder

The Microsoft.EntityFrameworkCore.ModelBuilder to use to build the model.

Remarks

See Database migrations for more information and examples.

Down(MigrationBuilder)

Builds the operations that will migrate the database 'down'.

protected virtual void Down(MigrationBuilder migrationBuilder)

Parameters

migrationBuilder MigrationBuilder

The MigrationBuilder that will build the operations.

Remarks

That is, builds the operations that will take the database from the state left in by this migration so that it returns to the state that it was in before this migration was applied.

This method must be overridden in each class that inherits from Migration if both 'up' and 'down' migrations are to be supported. If it is not overridden, then calling it will throw and it will not be possible to migrate in the 'down' direction.

See Database migrations for more information and examples.

Up(MigrationBuilder)

Builds the operations that will migrate the database 'up'.

protected abstract void Up(MigrationBuilder migrationBuilder)

Parameters

migrationBuilder MigrationBuilder

The MigrationBuilder that will build the operations.

Remarks

That is, builds the operations that will take the database from the state left in by the previous migration so that it is up-to-date with regard to this migration.

This method must be overridden in each class that inherits from Migration.

See Database migrations for more information and examples.