Project

General

Profile

How to specify NotNull constraint of a DBO field?

Added by Plug Gulp 3 months ago

How do I specify a not null constraint on a field? I don't see any option to specify that in the Wt::Dbo::field function. Is there any other way to do that?


Replies (1)

RE: How to specify NotNull constraint of a DBO field? - Added by Bruce Toll 3 months ago

I believe that Dbo will create table fields as not null by default. This can be seen in the generated SQL in https://www.webtoolkit.eu/wt/doc/tutorial/dbo.html. However, you can declare a field with std::optional (or boost::optional) to indicate that null values are supported. See the "Detailed Description" section under: https://www.webtoolkit.eu/wt/doc/reference/html/structWt_1_1Dbo_1_1sql_*value*_traits.html. There are also some usage examples with optional types in the Wt source in test/dbo/DboTest.C.

    (1-1/1)