Skip to content

Document that required columns are created nullable when table splitting #3750

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
ajcvickers opened this issue Mar 2, 2022 · 3 comments
Open

Comments

@ajcvickers
Copy link
Contributor

See dotnet/efcore#27516

The issue here is that our guidance is to introduce a required property in optional dependents. However, when table splitting, which is the default for owned types, Migrations will create a nullable column with a null default for this property. This makes all existing dependents effectively disappear. We need to document that the existing rows need to be populated with a non-null value so that they are detected as existing.

@IndigoHealth
Copy link

Oh! So just to expand on @ajcvickers comment... This issue (having a NULL value in the database in a column mapped to a non-nullable C# data type) only affects existing data. Data committed to the database after the new column has been added will get a non-null value for the new column assuming it is mapped to a non-nullable C# data type.

We need to document that the existing rows need to be populated with a non-null value

Is this "how it's supposed to work"? You're saying that we need to just know (or be told) to run a query or write some special-purpose code every time we add a non-nullable property to an owned entity in the data model? That's a disaster just waiting to happen. (Although the bright-yellow highlighted warning when we run the migration certainly gets our attention. If the warning gave us better guidance then, yeah, it's a breaking change with a manual fix. A little less than optimal but workable...)

@ajcvickers
Copy link
Contributor Author

Is this "how it's supposed to work"? You're saying that we need to just know (or be told) to run a query or write some special-purpose code every time we add a non-nullable property to an owned entity in the data model?

Typically it just requires editing the migration. This issue is to make sure to document this better. dotnet/efcore#25359 is to make the overall behavior better.

@syska
Copy link

syska commented Oct 4, 2022

That's a disaster just waiting to happen.

Well ... I guess it run in local dev and will make sure you know it's broken.

Could that be a better experience ... probably. But by far not a disaster unless I'm missing something.

@ajcvickers ajcvickers removed their assignment Aug 31, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants