Closed olijzenga closed 5 years ago
@olijzenga for this, I'd recommend implementing the prepare
method for the migration. The auto-migrations have very limited ability to infer things like this.
Check out the docs here: https://docs.vapor.codes/3.0/fluent/migrations/#custom-migrations
Lmk if you have any other questions, thanks :)
I am having an issue with storing the following model in my database:
Where CiString36 is defined as:
When I try to store a
User
withname
set tonil
in my database, I get the error:When I look at the SQL queries that are executed when creating the table, I see that the NOT-NULL constraint is not properly handled:
It recognizes that
CiString36
Encodes and Decodes to a string, and creates the column of type text. However, thename
field fromUser
is set to NOT NULL despitename
being an optional variable.Optional types seem to work fine in all other situations. Only types that encode and decode using a SingleValuedContainer have this issue.
Is this intended behaviour? And if so, is there a different way to do this?
Edit: Also if I remove the NOT NULL constraint from the
name
column manually using for example PGAdmin, everything works fine again until I recreate the table.