0
votes

I am using postgresql and sqlalchemy for my flask project.

I recently partitioned one of my big tables based on created_on using postgresql triggers.

But now if a try to insert a record into master table with db.session.add(obj) in sqlalchemy, i am getting error saying

Instance has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.

Here I am using a sequence to increment my primary key. Please help me with this.

1
Please help in helping you and provide a minimal reproducible example.Ilja Everilä

1 Answers

0
votes

use autoincrement=True while defining your column example in my code sno is an autoincrement field :

class Contact(db.Model):
     sno = db.Column(db.Integer, primary_key=True,autoincrement=True)