![]() Since you added a DbSet to the database context, Entity Framework Core will create an Items table (with columns that match a TodoItem) when you apply the migration. ![]() The Up method runs when you apply the migration to the database. Protected override void Down( MigrationBuilder migrationBuilder) Table.PrimaryKey( "PK_Items", x => x.Id) If you open your migration file, you'll see two methods called Up and Down:ĭata/Migrations/ _AddItems.cs protected override void Up( MigrationBuilder migrationBuilder) You can see a list of migrations with dotnet ef migrations list. Your new AddItem migration is prefixed with a timestamp when you create it. The first migration file (with a name like 00_CreateIdentitySchema.cs) was created and applied for you way back when you ran dotnet new. If you open up the Data/Migrations directory, you'll see a few files: ![]() These commands must be run from the project root directory (where the Program.cs file is). If you get an error like No executable found matching command "dotnet-ef", make sure you're in the right directory. This creates a new migration called AddItems by examining any changes you've made to the context. Since the context now includes a set (or table) that doesn't exist in the database, you need to create a migration to update the database: dotnet ef migrations add AddItems In the previous chapter, you added an Items set to the context. With migrations, you have a full history of modifications like adding or removing columns (and entire tables). They make it possible to undo (roll back) a set of changes, or create a second database with the same structure as the first. ![]() Migrations keep track of changes to the database structure over time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |