1
我在想這個任務是相當微不足道的,但我沒有運氣在Google上搜索它。如果我有一個User
表,那就有upload_list
關係成表Videos
,你怎麼清除upload_list
表呢?如何從SQLAlchemy關係子表中刪除所有行?
我構建這樣說:
class Users(base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
email = Column(String(100), unique=True)
password = Column(String(255))
fullname = Column(String(255))
photo = Column(String(255))
last_updated = Column(DateTime())
upload_lists = relationship('UploadLists', cascade="all, delete, delete-orphan")
class UploadLists(base):
__tablename__ = 'upload_lists'
id = Column(Integer, primary_key=True)
list_id = Column(String(255), unique=True)
user_id = Column(Integer, ForeignKey('users.id'))
user = relationship("Users")
videos = relationship('Videos', cascade="all, delete, delete-orphan")
class Videos(base):
__tablename__ = 'videos'
id = Column(Integer, primary_key=True)
video_id = Column(String(255), unique=True)
title = Column(String(255))
description = Column(String(255))
upload_date = Column(DateTime)
thumbnail_url = Column(Text())
thumbnail_file = Column(Text())
放下桌子並重新創建它? – IanAuld 2014-11-23 04:38:32
..但是其他用戶的所有其他'upload_lists'數據都將被刪除。 – swdev 2014-11-23 09:15:10