-1
我有一個表指定用戶,這裏是它的架構:MySQL TEXT或BLOB類型不能是唯一的嗎?
class User(db.Model):
__tablename__ = "Users"
id = db.Column(db.Integer, unique=True, primary_key=True)
firstname = db.Column(db.String(64), unique=False, nullable=False)
lastname = db.Column(db.String(64), unique=False, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(93), unique=False, nullable=False)
phone = db.Column(db.String(10), unique=True, nullable=False)
publickey = db.Column(db.Text, unique=True, nullable=True)
isitseller = db.Column(db.Boolean, unique=False, nullable=False)
money = db.Column(db.Float, unique=False, nullable=False)
def __init__(self, firstname, lastname, email, password, phone, publickey, isitseller):
self.firstname = firstname
self.lastname = lastname
self.email = email
self.password = generate_password_hash(password)
self.phone = phone
self.publickey = publickey
self.isitseller = isitseller
self.money = 0.00
def check_password(self, password):
return check_password_hash(self.password, password)
def __repr__(self):
return '<User %r>' % self.firstname + " " + self.lastname
但是當我嘗試創建用戶表db.create_all()它輸出我
(_mysql_exceptions.OperationalError) (1170, "BLOB/TEXT column 'publickey' used in key specification without a key length") [SQL: '
CREATE TABLE `Users` (
id INTEGER NOT NULL AUTO_INCREMENT,
firstname VARCHAR(64) NOT NULL,
lastname VARCHAR(64) NOT NULL,
email VARCHAR(120) NOT NULL,
password VARCHAR(93) NOT NULL,
phone VARCHAR(10) NOT NULL,
publickey TEXT,
isitseller BOOL NOT NULL,
money FLOAT NOT NULL,
PRIMARY KEY (id),
UNIQUE (id),
UNIQUE (email),
UNIQUE (phone),
UNIQUE (publickey),
CHECK (isitseller IN (0, 1))
)
']
據我瞭解我需要使用任何TEXT或BLOB類型的colunm,但我該怎麼做?或者使用TEXT或BLOB作爲UNIQUE的任何方式?
'publickey'必須是唯一的,可以是'null'? ;)儘管如此,真正的錯誤可以在https://stackoverflow.com/questions/1827063/mysql-error-key-specification-without-a-key-length – GuyT