Conversation
|
FYI _ stumbled across this trying to debug SQLModel using DB2. The create table SQL ends up using Not sure if that helps but DB2 doesn't like unbounded varchars |
|
A vote for me as well. This is, for many database centric applications, a significant issue if the max_length for a string does not create a corresponding text(max_length) or varchar(max_length) etc in the table. I sthere any way this can be escalated, or would you accept an updated pull request from me if I was able to resolve it? |
|
Looking to use max_length behavior as well. The PR looks almost ready! Bump @tiangolo |
|
@proever, thanks for your efforts! Current version of SQLModel already handles this and uses Thanks again! |
Currently, when
max_lengthis specified in aField, it has no real effect on the corresponding SQL schema (#126, #746). As pointed out by @chris-beedie, this is because the configuredmax_lengthis stored as anannotated_types.MaxLen, rather than aPydanticMetadataobject, and is therefore ignored inget_field_metadata.This PR adds a simple extra check for that specific case. I have confirmed it works using PostgreSQL 16.2.
I also wanted to write a test for it, along the following lines:
Unfortunately, this doesn't work, as
sqlitedoes not actually enforce something likeVARCHAR(5).One solution would be to use a
testcontainer(see here) to run a PostgreSQL instance and test against that, but it would significantly increase the complexity & dependencies of the unit tests.