Opened 8 years ago

Closed 8 years ago

#6336 closed (duplicate)

models.TextField gives an error on syncdb, if unique set to true

Reported by: shabda Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: models
Cc: shabda.raaj@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


models.TextField is giving errors if unique=True

from django.db import models

class Category(models.Model):
    """Category under which a page is classified. ManyToMany relationship with pages."""
    text = models.TextField(max_length = 100, unique = True)

Get this model in, and run syncdb. You will get an error like

Traceback (most recent call last):
  File "F:\djangoprojects\testme\", line 11, in ?
  File "C:\Python24\lib\site-packages\django\core\management\", line
272, in execute_manager
  File "C:\Python24\lib\site-packages\django\core\management\", line
219, in execute
  File "C:\Python24\lib\site-packages\django\core\management\", line 72,
in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python24\lib\site-packages\django\core\management\", line 86,
in execute
    output = self.handle(*args, **options)
  File "C:\Python24\lib\site-packages\django\core\management\", line 168,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python24\lib\site-packages\django\core\management\commands\"
, line 74, in handle_noargs
  File "C:\Python24\lib\site-packages\django\db\backends\", line 18, in e
    return self.cursor.execute(sql, params)
  File "C:\Python24\Lib\site-packages\MySQLdb\", line 166, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python24\Lib\site-packages\MySQLdb\", line 35, in defau
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1170, "BLOB/TEXT column 'text' used in key
specification without a key length")

Change the type to SlugField or remove the unique and try syncdb, you will get no errors.

Change History (2)

comment:1 Changed 8 years ago by shabda

  • Cc shabda.raaj@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by Simon Greenhill <dev@…>

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #2495

Note: See TracTickets for help on using tickets.
Back to Top