I have the following Flask-SQLAlchemy schema:
class User(db.Model, UserMixin):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), nullable=False, unique=True)
password = db.Column(db.String(255), nullable=False, server_default="")
email = db.Column(db.String(254), nullable=False, unique=True)
confirmed_at = db.Column(db.DateTime())
is_enabled = db.Column(db.Boolean(), nullable=False, default=False)
def is_active(self):
return self.is_enabled
Which generates the SQL (I'm using MySQL):
CREATE TABLE users (
id INTEGER NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NOT NULL,
password VARCHAR(255) NOT NULL DEFAULT '',
email VARCHAR(254) NOT NULL,
confirmed_at DATETIME,
is_enabled BOOL NOT NULL,
PRIMARY KEY (id),
UNIQUE (username),
UNIQUE (email),
CHECK (is_enabled IN (0, 1))
)
However, this gives me the error "Specified key was too long; max key length is 767 bytes".
Note that this is not a duplicate of Can't create_all Flask-SQLAlchemy - specified key was too long; that question suggested shortening unique column lengths to <255 characters, and I have tried that with no success.
I would like, if possible, to keep the email field at 254 characters as that is the max length as defined by the spec.