❔ After I make a string nullable (by adding the ?) and add the migration then update my database...
It still shows as not nullable, why?
21 Replies
Using EntityFramework
Still shows like this in the migration:
You don't have any config that'd contradict that nullability?
Hmm. I don't think so. Where would I look?
the nullable part in AlterColumn is changed, no?
it went from
nullable: false
to nullable: true
note that string?
isn't actually a unique generic typetheres two fiels here, title is still nullable false
oh, yeah, now I see
I thought those were the same for some reason, must just be tired
no worries
I have a required attribute on top of it/ Does that change anything?
I thought it dind't from research I did
I thought that the required attribute only affected the validation of the model
hover over required, what's the class
Yeah, it's the required attribute.
did you enable NRT after the fact?
was it disabled before?
NRT?
nullable reference types
or is this new
this?
<Nullable>enable</Nullable>
It's been there from the start
I'm goign to remove the attribute and see what happens
it should work
with both, besides you need required right
for validations
Yup. It's nullable now. Really should have tried that before.
I removed the attribute.
So it's not working as it should you think?
it seems as they are incompatible
so you can do this
Stack Overflow
Nullable property to entity field, Entity Framework through Code First
Using the data annotation Required like so:
[Required]
public int somefield {get; set;}
Will set somefield to Not Null in database, How can I set somefield
to allow NULLs?, I tried setting it thr...
to be required, and nullable in the database
but it makes little sense, if you logic prevents it from being null, why would it be nullable
see the discrepancy ?
maybe that's the logic behind it
Yes. I was following some notes from a tuto I saw a while back. Logically, I thought about that but... I don't know enough to contradict it. But yeah, I think this is fine. I don't need it to be nullable.
thank you everybody
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.