value too long for type character varying(N)

前端 未结 2 1231
后悔当初
后悔当初 2020-12-19 14:09

My model has a SlugField. When I try to save an instance of this model with the slug field set to a string which is longer than the field\'s max_length paramete

2条回答
  •  情书的邮戳
    2020-12-19 14:22

    You can just add something in your view that tests to see if the slug will be >50 characters, and if so truncates it.

    if len(content) >50:
        content = content[:50]
    else:
        pass
    slug = content
    

提交回复
热议问题