0
        .I created project with .net core 6. 
     GroupImageName is nullable but when I do migration, this property is created non-nullabe,also for example, posts property is created non-nullable.

what is the problem? How can I resolve it?


1
  • 1
    Please upload code in text instead in images. Images can't be searched and therefore aren't useful to future readers, harder to read than text. Commented Sep 14, 2022 at 10:28

1 Answer 1

1

To make a nullable properties from code first you have to use Nullable<string> or string? which makes your property nullable in database after migration

E.g. in your case your model looks like below:

PostGroup.CS

Public class PostGroup
{
   public int GroupId{get;set;}
   public string GroupName {get;set;}
   public string? GroupImageName {get;set;}
   .
   .
   .
   n so on properties
}

after making above change just run the command like below from PMC

add-migration
update-database

above stapes will make your properties nullable in db after successful migration

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.