Replying to this and the other emails in the thread: Django should not be settling low arbitrary limits for the sake of a database I'm not even using, that's just crazy. Limits as high as 120 are not "big enough for anyone", and will cause problems. (I can give lots of examples). Maximum field length is a critical value that must not be left to some default, because as soon as you come to interoperate with other systems, it *does* matter.
So, this needs to be explicit. We also need to cover the case of unlimited length Charfield for the databases that support it. This can be covered with a simple sentinel value UNLIMITED_LENGTH or similar. This is a 4th option not listed below. We could also potentially add another sentinel like DB_MAX_UNICODE_SAFE_LENGTH that works as you expect and is clearly documented, for the sake of 3rd party apps, and comes with the caveat that it produces different behaviour on different databases. Explicit is better than implicit etc., and in this case there is simply no sensible default behaviour that will cover all our use cases. Luke On 27 February 2016 12:55:23 GMT+00:00, Wim Feijen <[email protected]> wrote: >Hi guys, > >I'd like to reach consensus about >https://code.djangoproject.com/ticket/14094 > >In the discussion, I saw three options: > >1. Adding a default max_length = None, which may in practice differ per > >database backend. >2. Adding a default max_length of a value which can be used across >databases. Lengths which have been mentioned are: 100, 128, 191 and 255 > >characters and 4000 bytes. >3. Keep everything as is, being as explicit as possible. > >Option 1 does not allow for apps and data to be reused across several >apps >and several core developers do not support this idea. > >I'm in favour of option 2, because it makes for shorter code and more >importantly, it helps programmers choose a value which actually can be >reused across multiple databases (I didn't know about the possible >limit of >191 characters on mysql! Did you?). > >I dislike how it is now (option 3), and I don't think it is beneficial >here >to force people to be explicit, because people are now using arbitrary >values anyway. 255 is commonly used, the poll app of the Django >tutorial >uses 200. Actually I believe it is a big mess in practice, I see >defaults >of 100, 200, 255, 300, 1000 seemingly randomly used. For example, try >searching for CharField in your favourite apps or CMSes. > >In addition, adding a default for max_length still allows to be >explicit >when it matters. And it makes life simple when it doesn't matter, and >simple is better than complex. > >What would be a good default then? I am in favour of making it as big >as >possible while still working on all databases, which would either be >191 of >255 in order to support mysql. > >Wim > > > >On Wednesday, 23 September 2015 19:02:20 UTC+2, Tom Christie wrote: >> >> I'm with Tom here. >> Forcing `max_length` to always be set on CharField feels like the >right >> decision. Having a default there seems unnecessary obscure, and more >likely >> to lead to untested/unnoticed failure cases. >> It *could* be that we'd allow `max_length=None` to explicitly turn >off the >> validation, but I'm not sure if that's better than forcing developers >who >> want unvalidated lengths to use TextField. >> > >-- >You received this message because you are subscribed to the Google >Groups "Django developers (Contributions to Django itself)" group. >To unsubscribe from this group and stop receiving emails from it, send >an email to [email protected]. >To post to this group, send email to >[email protected]. >Visit this group at https://groups.google.com/group/django-developers. >To view this discussion on the web visit >https://groups.google.com/d/msgid/django-developers/a2cfad14-4384-4118-bc28-d89099433ca5%40googlegroups.com. >For more options, visit https://groups.google.com/d/optout. -- Sent from my phone -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/EBD26DDE-B91E-4CB6-950F-8E67B98AB97E%40cantab.net. For more options, visit https://groups.google.com/d/optout.
