column 'title' used in key specification without a key length

311 views
Skip to first unread message

Victor Lin

unread,
Mar 1, 2008, 11:36:12 AM3/1/08
to sqlalchemy
Hi, I wanna use SQLAchemy to create a table in MySQL database,
This is the code I worte:

class ChannelTable(Database.Table):

def __init__(self, database):
Database.Table.__init__(self, database, Channel)

def getTable(self):
"""Get table definition to create

@return: table definition
"""
return Table('channel', self.database.meta,
Column('id', Integer, primary_key=True),
Column('title', Text, nullable=False, unique=Tru),
Column('category_id', Integer,
ForeignKey('category.id'))
)

But once I try to create this table, here comes the problem

sqlalchemy.exceptions.OperationalError: (OperationalError) (1170,
"BLOB/TEXT column 'title' used in key specification without a key
length") '\nCREATE TABLE category (\n\tid INTEGER NOT NULL
AUTO_INCREMENT, \n\ttitle TEXT(32) NOT NULL, \n\tPRIMARY KEY (id), \n
\t UNIQUE (title)\n)\n\n' {}

It says that I should set the length of key of title. I know I can
solve this problem by setting the length of key.
But the problem is : How to set the length for key? I can't find
method to do so in document.

Thanks.
Victor Lin.

Michael Bayer

unread,
Mar 2, 2008, 12:45:56 PM3/2/08
to sqlal...@googlegroups.com

On Mar 1, 2008, at 11:36 AM, Victor Lin wrote:

>
>
> It says that I should set the length of key of title. I know I can
> solve this problem by setting the length of key.
> But the problem is : How to set the length for key? I can't find
> method to do so in document.

try using :

from sqlalchemy.databases.mysql import MSText

MSText(length=<somelength>)


since "length" is not standard for the Text type.

Reply all
Reply to author
Forward
0 new messages