Aug-28-2020, 12:11 AM
Hi,
I'm trying learn python and flask by building a simple web application.
The user will enter the product details in web application form which will be inserted in to postgres table. When I enter the product details and click submit i see below error
Error :
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "product_code" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null, null).
app.run(debug=True)
[/python]
Can you please advice on the error
Thank
kt
I'm trying learn python and flask by building a simple web application.
The user will enter the product details in web application form which will be inserted in to postgres table. When I enter the product details and click submit i see below error
Error :
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "product_code" violates not-null constraint
DETAIL: Failing row contains (null, null, null, null, null).
class BkpFulfilmentProductProvider(db.Model):
""" Databae Model for FUlfilment Product Provider"""
__tablename__ = 'bkp_fulfilment_product_provider'
product_code = db.Column(db.String(100), primary_key=True)
fulfilment_provider_code = db.Column(db.String(100))
is_primary = db.Column(db.Boolean)
on_hand_stock = db.Column(db.Integer)
on_order_stock = db.Column(db.Integer)
@app.route('/')
def fulfilment_view():
return render_template('Ful_Product_Provider.html')
@app.route('/Fulfilment', methods=['POST'])
# if request.method == "POST":
def fulfilmentproductprovider():
# from models import BkpFulfilmentProductProvider
if request.method == 'POST':
prod_cd = request.form.get('product_code')
ful_provider_cd = request.form.get('fulfilment_provider_code')
primary = request.form.get('is_primary')
stock_in_hand = request.form.get('on_hand_stock')
ordered_stock = request.form.get('on_order_stock')
fulfil = BkpFulfilmentProductProvider(product_code=prod_cd, fulfilment_provider_code=ful_provider_cd,
is_primary=primary, on_hand_stock=stock_in_hand, on_order_stock=ordered_stock)
db.session.add(fulfil)
db.session.commit()
return render_template('Ful_Product_Provider.html')
[python]if __name__ == '__main__':app.run(debug=True)
[/python]
Can you please advice on the error
Thank
kt
