Python Forum
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation)
#1
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).


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
Reply


Messages In This Thread
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) - by py_kt - Aug-28-2020, 12:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask error sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint pythonpaul32 2 8,002 Feb-21-2023, 03:13 AM
Last Post: noisefloor

Forum Jump:

User Panel Messages

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