python - Dependency rule tried to blank-out primary key column in SQL-Alchemy when trying to delete record -


i have many 1 relationship between userownedshare table , share table.

when delete userownedshare entry database following error: assertionerror: dependency rule tried blank-out primary key column 'share.ticker'

this makes sense ticker field in userownedshare foreign key in share table. cannot work out how fix error. think want set cascading deletion when share entry orphaned cannot work out how this, have read documentation end different types of errors think missing trivial. hope can help, thanks!


here code:

class userownedshare(db.model):     id = db.column(db.integer, primary_key=true)     ticker = db.column(db.string(20), db.foreignkey('share.ticker'))     user = db.column(db.string, db.foreignkey('user.username'))     quantity = db.column(db.integer, nullable=false)     dividends = db.column(db.float, server_default="0.0")     triggerlevel = db.column(db.integer)     smsalert = db.column(db.boolean)     emailalert = db.column(db.boolean)     portfolioid = db.column(db.string(50))     name = db.relationship('share', backref='userownedshare' ,  foreign_keys=[ticker])  class share(db.model):     id = db.column(db.integer)     name = db.column(db.string(50), nullable=false)     ticker = db.column(db.string(50), db.foreignkey('userownedshare.ticker'), primary_key=true)     tickermatch = db.relationship('userownedshare', backref='share',  foreign_keys=[ticker]) 

ok, after trial , error worked out. needed add cascade="all, delete-orphan", tickermatch relationship in share class.

but needed add lazy="joined" name relationship in userownedshare class

class userownedshare(db.model): id = db.column(db.integer, primary_key=true) ticker = db.column(db.string(20), db.foreignkey('share.ticker')) user = db.column(db.string, db.foreignkey('user.username')) quantity = db.column(db.integer, nullable=false) dividends = db.column(db.float, server_default="0.0") triggerlevel = db.column(db.integer) smsalert = db.column(db.boolean) emailalert = db.column(db.boolean) portfolioid = db.column(db.string(50)) name = db.relationship('share', backref='userownedshare',  foreign_keys=[ticker], lazy="joined")  class share(db.model): id = db.column(db.integer) name = db.column(db.string(50), nullable=false) ticker = db.column(db.string(50), db.foreignkey('userownedshare.ticker'), primary_key=true) tickermatch = db.relationship('userownedshare', backref='share', cascade="all, delete-orphan", lazy="joined") 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -