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.