Opened 7 years ago

Closed 7 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:

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 Changed 7 years ago by shabda

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

comment:2 Changed 7 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