Opened 16 years ago

Closed 16 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: dev
Severity: Keywords: models
Cc: shabda.raaj@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 models.py, and run syncdb. You will get an error like

Traceback (most recent call last):
  File "F:\djangoprojects\testme\manage.py", line 11, in ?
    execute_manager(settings)
  File "C:\Python24\lib\site-packages\django\core\management\__init__.py", line
272, in execute_manager
    utility.execute()
  File "C:\Python24\lib\site-packages\django\core\management\__init__.py", line
219, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python24\lib\site-packages\django\core\management\base.py", line 72,
in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python24\lib\site-packages\django\core\management\base.py", line 86,
in execute
    output = self.handle(*args, **options)
  File "C:\Python24\lib\site-packages\django\core\management\base.py", line 168,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python24\lib\site-packages\django\core\management\commands\syncdb.py"
, line 74, in handle_noargs
    cursor.execute(statement)
  File "C:\Python24\lib\site-packages\django\db\backends\util.py", line 18, in e
xecute
    return self.cursor.execute(sql, params)
  File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 35, in defau
lterrorhandler
    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 by Shabda, 16 years ago

Cc: shabda.raaj@… added

comment:2 by Simon Greenhill <dev@…>, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #2495

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