Closed radaced closed 1 month ago
customConstraint
resets a columns constraints, so although by default a text()
column has a NOT NULL
constraint, customConstraint
removes it.
So when you remove the customConstraint
constraint, it reverts to being NOT NULL
.
See https://drift.simonbinder.eu/docs/getting-started/advanced_dart_tables/#custom-constraints
After seeing build warnings that nullability is not specified I saw that there are also ColumnBuilder options like unique() oder references(...).
Perhaps we should make the warnings clearer then? This behavior is what the warning was trying to explain. The columns appear to be non-nullable, but they're not. Now that the definition is fixed, the old schema is wrong.
If you didn't actually insert non-nullable values, a simple m.alterTable(TableMigrations(affectedTable))
migration should do the trick.
Thanks for the replies and help.
I have the following table specified:
After seeing build warnings that nullability is not specified I saw that there are also ColumnBuilder options like
unique()
oderreferences(...)
.I changed the table specification to this:
The build warnings disappeared and everything got regenerated nicely.
old:
new:
Apart from these changes I did some actual model changes and generated files to write a migration test. While running the test I got the following error:
If I interpret this correctly it seems that the nullability specification for these fields are somehow missing although I didn't change anything about the nullability and by default they should not be nullable. I don't see a possibility to specify explicit
nonnullable()
or similar (as opposite to thenullable()
option).I assume this is a bug or is this somehow not the intended usage?
I used drift version 2.18.0, but I also couldn't see any fixes regarding to this in newer versions.
Any help or guidance is well appreciated and let me know if you need more infos.