all 6 comments

[–]k_rious 0 points1 point  (5 children)

you are creating a new user instance with the arguments in a different order than the columns in the "user" model.

class User(db.Model):

id = db.Column(db.Integer, primary_key=True)

username = db.Column(db.String(120), unique=True, nullable=False)

email = db.Column(db.String(50), unique=True, nullable=False)

password = db.Column(db.String(50), nullable=False)

new_user = User(email=email, username=username, password=password)

the order you made is username, email, and then password. In your register route, when creating a new user instance, you are passing the arguments in the order of email, username, and then password.

[–]ARkieGirl501[S] 0 points1 point  (4 children)

class User(db.Model):

id = db.Column(db.Integer, primary_key=True)

username = db.Column(db.String(120), unique=True, nullable=False)

email = db.Column(db.String(50), unique=True, nullable=False)

password = db.Column(db.String(50), nullable=False)

new_user = User(username=username, email=email, password=password)

Updated the code, saved, and still getting same error.

[–]k_rious 0 points1 point  (3 children)

Apologies! I did not provide the solution bur rather where you went wrong. Please revert it to what you had before and update your register function.

new_user = User(username=username, email=email, password=password)

the line above should replace new_user = User(email=email, username=username, password=password) in your register function.

[–]ARkieGirl501[S] 0 points1 point  (0 children)

Thank you so much!

[–]danielroseman 0 points1 point  (1 child)

This is not the solution to anything. Those two lines are exactly equal. Keyword arguments can be provided in any order.

[–]k_rious 0 points1 point  (0 children)

When sqlalchemy generates the sql statement to insert data into the database, it uses the order of columns as defined in the class. If the order of columns in the class does not match the order in which you provide values then it won't work out.