text stringlengths 0 13.4k |
|---|
commands must be run from the project root directory (where the |
Program.cs file is). |
If you open up the Data/Migrations directory, you'll see a few files: |
53 |
Create a migration |
The first migration file (with a name like 00_CreateIdentitySchema.cs ) |
was created and applied for you way back when you ran dotnet new . |
Your new AddItem migration is prefixed with a timestamp when you |
create it. |
You can see a list of migrations with dotnet ef migrations list . |
If you open your migration file, you'll see two methods called Up and |
Down : |
Data/Migrations/_AddItems.cs |
protected override void Up(MigrationBuilder migrationBuilder) |
{ |
// (... some code) |
migrationBuilder.CreateTable( |
name: "Items", |
columns: table => new |
{ |
Id = table.Column<Guid>(nullable: false), |
DueAt = table.Column<DateTimeOffset>(nullable: true), |
IsDone = table.Column<bool>(nullable: false), |
Title = table.Column<string>(nullable: true) |
}, |
constraints: table => |
{ |
table.PrimaryKey("PK_Items", x => x.Id); |
}); |
// (some code...) |
} |
protected override void Down(MigrationBuilder migrationBuilder) |
{ |
// (... some code) |
migrationBuilder.DropTable( |
name: "Items"); |
// (some code...) |
} |
54 |
Create a migration |
The Up method runs when you apply the migration to the database. |
Since you added a DbSet<TodoItem> to the database context, Entity |
Framework Core will create an Items table (with columns that match a |
TodoItem ) when you apply the migration. |
The Down method does the opposite: if you need to undo (roll back) the |
migration, the Items table will be dropped. |
Workaround for SQLite limitations |
There are some limitations of SQLite that get in the way if you try to run |
the migration as-is. Until this problem is fixed, use this workaround: |
Comment out or remove the migrationBuilder.AddForeignKey lines |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.