Add "Apply migrations" section to MVC validation tutorial#36817
Draft
Add "Apply migrations" section to MVC validation tutorial#36817
Conversation
…rted versions Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add migration for applying validation rules to schema
Add "Apply migrations" section to MVC validation tutorial
Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ASP.NET Core MVC validation tutorial (Part 9) was missing guidance on running an EF Core migration after adding validation attributes that affect the database schema — leaving the model and DB schema out of sync. The Razor Pages equivalent tutorial already had this section.
Changes
validation.md(≥ aspnetcore-10.0) and versioned includes for 6.0–9.0 (validation6.md–validation9.md): Added## Apply migrationssection after "Using DataType Attributes" and before "Additional resources"The new section explains that
[Required]→NOT NULLand[StringLength(60)]→nvarchar(60), and provides tabbed migration commands:Visual Studio: incremental migration via PMC
Visual Studio Code: delete-and-recreate (required due to SQLite
ALTER TABLElimitations, consistent with Part 8)Updated
ms.dateand addedai-usage: ai-assistedtovalidation.mdfrontmatterOriginal prompt
This section details on the original issue you should resolve
<issue_title>For consistency: add-migration after applying validation rules</issue_title>
<issue_description>It's worth mentioning that some validation rules must be applied to the DB schema for consistency by adding a new migration. e.g. add-migration AddingNewRules
Mainly, the following two attributes affect the schema:
1- [Required] will alter the relevant column and make it not null
2- [StringLength(60)] will alter the type of the column and make it nvarchar(60)
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Comments on the Issue (you are @copilot in this section)
@wadepickett ## 🤖 AI Triage SummaryThis preliminary assessment report was run by: @wadepickett
Date: 2026-02-27
Issue: 10429
Model: GitHub Copilot
Issue Analysis: Add migration step after applying validation rules for database schema consistency
✅ Issue Validation
Status: Valid and actionable
📋 Issue Summary
The issue requests that the Part 9 "Add validation" tutorial mention running an EF Core migration after adding validation attributes that affect the database schema—specifically
[Required](makes columns NOT NULL) and[StringLength(60)](changes columns tonvarchar(60)).After a careful walkthrough of all 10 parts of the tutorial series, the issue's core observation is confirmed:
Tutorial Schema Evolution (verified)
Movieclass created (no validation attrs)InitialCreateTitle nvarchar(max) NULL,Genre nvarchar(max) NULL[Display],[DataType],[Column(TypeName)][Display]/[DataType]don't affect schema;[Column]already matchedRatingpropertyAdd-Migration RatingRating nvarchar(max) NULLcolumn[Required],[StringLength(60)],[StringLength(30)],[StringLength(5)],[RegularExpression],[Range]nvarchar(max), NULLdespite model constraintsResult: After Part 9, the application enforces validation at the client and server level, but the database schema does not enforce
NOT NULLor length constraints. This is the exact gap the issue author identified.Why the tutorial "works" without the migration
Part 9 begins with a "Delete the previously edited data" section (Line 30-33) that instructs users to delete all movies so seed data can repopulate. This prevents runtime exceptions from existing NULL data conflicting with
[Required], but it does not update the database schema itself. The app-level validation prevents bad data from reaching the database, so the tutorial "works" — but the schema and model are out of sync.📁 Potentially Affected Files
aspnetcore/tutorials/first-mvc-app/validation.mdaspnetcore/tutorials/first-mvc-app/validation/includes/validation9.md🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.