Python Forum
error while inserting values into a table from form in flask in postgreSQL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error while inserting values into a table from form in flask in postgreSQL
#1
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}]
Reply
#2
(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 :)
Reply
#3
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):
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 248 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  How to Connect to PostgreSQL Through Jump Server and SSH Tunnel using Python? nishans 1 964 Jan-02-2024, 10:37 AM
Last Post: khanzain
  pyscript index error while calling input from html form pyscript_dude 2 973 May-21-2023, 08:17 AM
Last Post: snippsat
  python script for inserting rows into hbase table lravikumarvsp 7 7,097 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
Photo How to select NULL and blank values from MySQL table into csv python300 9 2,411 Dec-27-2022, 09:43 PM
Last Post: deanhystad
  store all variable values into list and insert to sql_summary table mg24 3 1,130 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  Trying to use 2 values from excel in my script but getting error.. cubangt 3 1,666 May-11-2022, 07:12 AM
Last Post: normanwolf
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,623 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  Error creating database with python and form? shams 3 2,366 Aug-02-2021, 02:00 PM
Last Post: deanhystad
  Error using mariadb select query with form in python? shams 2 1,997 Jul-29-2021, 12:30 PM
Last Post: shams

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020