0

I am solving the week 9 problem using python. And I am interested in knowing how to deal with the error below using the if and elif?

For example:

rows = db.execute("SELECT username FROM users WHERE username = ?", str(username))

if rows == null:
return render_template("sorry.html")

Erro:

ValueError: UNIQUE constraint failed: users.username

Thanks

0

Each username in a database must be unique, otherwise, the code thinks you are re-registering a username that already existed. I can't tell much more without looking at the code, I hope that helps.

1
  • Exactly, the username must be unique in the database, but what I want is to detect this error and prevent internal server error, I want to redirect to another route ('/ sorry') I add the query on the post.
    – Code Maker
    May 15 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .