"WITH VALUES" support for default constraint

Open
#12,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp, sql
Domain
databases

Research direction

Start by examining how EF Core migrations generate a new nullable column with a model default, then compare that behavior with SQL Server's WITH VALUES handling for default constraints. Done means the migration can initialize existing rows to the configured default when adding the column, with the resulting behavior documented or covered by an appropriate migration test.

Written by the indexing model from the issue text.

Description

area-migrations customer-reported needs-design

This is a question/clarification.
I added new optional property to my model, which resulted in a new nullable column. The property also has default value defined. I also have a migration for this change, which adds new column. Now, what I want to achieve is when the migration adds new column, it should initialize it to the default value I specified. Instead, because the column is nullable, it's initialized to NULL. With raw SQL this could be accomplished using "WITH VALUES" added to the default constraint definition (more on this here). Is there any way to configure my model to have the same behaviour?

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.