Python Forum
error while inserting values into a table from form in flask in postgreSQL - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: error while inserting values into a table from form in flask in postgreSQL (/thread-3565.html)



error while inserting values into a table from form in flask in postgreSQL - sahilsiddharth - Jun-03-2017

my question here
forms.py---
class SignUpForm(Form):
first_name = StringField('First name', validators=[DataRequired("Please enter your first name")])
last_name = StringField('Last name', validators=[DataRequired("Please enter your last name")])
email = StringField('email', validators=[DataRequired("Please enter valid email address"), Email("Enter valid email address")])
password = PasswordField('password', validators=[DataRequired("Please enter your password"),Length(min=6, message="Password must be minimum 6 characters")])
submit=SubmitField('Sign Up')
python code -  
     newuser = USERS(form.first_name.data, form.last_name.data, form.email.data, form.password.data )
     db.session.add(newuser)
     db.session.commit()
     return 'Success!'
Error --
Error:
sqlalchemy.exc.IntegrityError sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) null value in column "FIRST_NAME" violates not-null constraint DETAIL:  Failing row contains (11, null, null, null, null). [SQL: 'INSERT INTO "USERS" ("FIRST_NAME", "LAST_NAME", "EMAIL_ID", "PWDHASH") VALUES (%(FIRST_NAME)s, %(LAST_NAME)s, %(EMAIL_ID)s, %(PWDHASH)s) RETURNING "USERS"."USER_ID"'] [parameters: {'FIRST_NAME': None, 'LAST_NAME': None, 'EMAIL_ID': None, 'PWDHASH': None}]



RE: error while inserting values into a table from form in flask in postgreSQL - nilamo - Jun-03-2017

(Jun-03-2017, 07:55 AM)sahilsiddharth Wrote: sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) null value in column "FIRST_NAME" violates not-null constraint
Don't insert nulls. You're welcome :)


RE: error while inserting values into a table from form in flask in postgreSQL - snippsat - Jun-03-2017

Quote:class SignUpForm(Form):
Flask-WTF has changes Form to FlaskForm.
Then not getting any values from client side form submit and insert to PostgreSQL will be wrong.
class SignUpForm(FlaskForm):


RE: error while inserting values into a table from form in flask in postgreSQL - sahilsiddharth - Jun-05-2017

After changing from Form to FlaskForm , getting same error . I can print the value of form.first_name.data, form.last_name.data, form.email.data, form.password.data but when it is going to add into the table , giving error .

Do i have to do migration in Flask like we have to do in django.