python - SQLAlchemy - Handling Constraint Failures -
with sqlalchemy, if have unique column in database eg, username:
username = db.column(db.string(50), unique=true)
when add row breaks constraint username i’m trying add exists, integrityerror thrown:
integrityerror: (integrityerror) (1062, u"duplicate entry 'test' key 'username'")
is possible instead map breaking of constraint custom exception? eg.usernameexistserror
i want able catch individual constraint breaks, , send response user. eg: "this username in use"
is possible? or next best thing?
any guidance appreciated :)
the next best thing might surrounding call try ... except
, parsing error message, , notifying user constructed error message.
along lines, try ... except
error , return custom error code flask's custom error pages.
Comments
Post a Comment