This is my user model :
class User(db.Model):
tablename = ‘Users’
USERID = db.Column(db.String(10), primary_key=True, server_default=db.FetchedValue())
PASS = db.Column(db.String(255), nullable=False)
USERNAME = db.Column(db.String(20), nullable=False, unique=True)
PHONE = db.Column(db.String(20), nullable=False, unique=True)
The code I used to add a new user :
new_user = User(USERNAME = username , PHONE = phone , PASS = password)
db.session.add(new_user)
db.session.commit()
Error :
Instance <User at 0x1b9fb6b7950> 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.
More information about the trigger :
The trigger runs BEFORE a row is inserted and it generates a unique code which is alphanumeric.
Rakesh B Sirvi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.