title: How to add unique constraint to big textfield in django?
body: <p>models.py:</p>
  
  <pre><code>class PageURL(models.Model):
      url = models.TextField(max_length=2048, unique=True)
  </code></pre>
  
  <p>Error during migrations:</p>
  
  <blockquote>
    <p>django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'url' used
    in key specification without a key length")</p>
  </blockquote>
  
  <p>I considered a CharField but Django said the max on that for this use case was 255 characters. Initially I just had <code>TextField(unique=True)</code> but decided to add a max_length which I heard was normally 2048 for URLs but that hasn't helped silence the errors.</p>
  
  <p>I tried CharField with no max_length and just a unique constraint set.</p>
  
  <blockquote>
    <p>core.PageURL.url: (fields.E120) CharFields must define a 'max_length'
    attribute. core.PageURL.url: (mysql.E001) MySQL does not allow unique
    CharFields to have a max_length > 255.</p>
  </blockquote>
  
  <p>The solution I've rigged is to go into phpMyAdmin and alter the structure by hand to varchar(2048) and add a unique constraint to it.</p>