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

OK, so after some trial and error I worked it out. I needed to add cascade="all, delete-orphan", to the tickermatch relationship in the Share class.

But I also needed to add lazy="joined" to the name relationship in the 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")