How to make a database column nullable in Entity Framework Core

If your using the code first approach in Entity Framework Core, you'll probably need to make some properties nullable in your database. Here's how you do it.

In your model, add ? to your class property you want to make nullable in the database.

public DateTime? UpdatedDate { get; set; }

Now, create and run a new migration.

dotnet ef migrations add MakeUpdatedDateNullable
dotnet ef database update

The UpdatedDate column should now be nullable in your database!

The Full Stack Dev Newsletter

The Full Stack Dev Avatar

Hey, I'm Wes. Every month I send a newsletter with articles on:

  • ​🔥 Hot Web Dev tips
  • 🎨 Web Design
  • 🔨 Product Development

As seen at the top of Hacker News, Indie Hackers, and Hacker Noon.