I think a problem with hashing names here is that it would break the whole 
`apps.get_model(<app_label>, <model_name>)` functionality that content 
types uses, as the model name stored in the db is not the actual name 
stored in the apps registry (and modifying the registry functionality feels 
like the wrong approach here).

> *contenttypes* should support all backends,  You need to remember about 
DB-restrictions, e.g. we cannot change `ContentType.model` to a `TextField` 
because TEXT columns cannot be used in unique constraints on MySQL. See similar 
discussion <https://groups.google.com/g/django-developers/c/h98-oEi7z7g> 
about `User.last_name`.

I think a key difference with the `User.last_name` example is that Django 
provides a way to avoid this all together by setting a custom User model. 
The ContentType model is much more tightly coupled, so unless we want to 
implement a similar way to override the ContentType model, it feels like we 
aught to be more accommodating with the max_length here.

With this in mind (and my awareness that me hitting this issue was an edge 
case already) perhaps the most straight forward solution would be to leave 
the `model` field as CharField but just set its max_length to 255. This 
would be consistent with the approach taken with `Permission.name` 
<https://code.djangoproject.com/ticket/8162>. Sort of feels like kicking 
the bucket down the road, but perhaps it is far enough down said road to no 
longer be an issue.

On Wednesday, 12 August 2020 05:51:58 UTC+12, charettes wrote:
>
> > Suffix-hashing long names like Simon suggests may not be 
> backwards-compatible. 
>
> Could you elaborate on that?
>
> Assuming model names > 100 characters never worked wouldn't only 
> suffix-hashing model names > 100 characters be backward compatible?
>
> Simon
>
> Le mardi 11 août 2020 à 12:05:46 UTC-4, Shai Berger a écrit :
>
>> AFAIK Postgres, in these cases, simply truncates the name. This means: 
>>
>> 1) Generating models with names longer than 63 characters on postgres 
>> is fragile. You may find yourself with more than one model trying to 
>> use the same table name. 
>>
>> 2) Suffix-hashing long names like Simon suggests may not be 
>> backwards-compatible. 
>>
>> My 2 cents, 
>> Shai. 
>>
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/57e57ee9-cc45-46bc-b205-fb87173109c5o%40googlegroups.com.

Reply via email to