[英]How do I get a SQLite query to return the id of a table when I have two tables that have an attribute named id?
[英]How to achieve that every record in two tables have different id?
我有兩個從基本表繼承的表(SQLALCHEMY模型)
class Base(object):
def __tablename__(self):
return self.__name__.lower()
id = Column(Integer, primary_key=True, nullable=False)
utc_time = Column(Integer, default=utc_time(), onupdate=utc_time())
datetime = Column(TIMESTAMP, server_default=func.now(), onupdate=func.current_timestamp())
以及繼承的表Person
和Data
如何實現每個Person和Data具有不同的ID,每個ID對於兩個表都是唯一的? (生成ID時要知道數據ID的人,反之亦然)
如果您使用的是Postgresql,Firebird或Oracle,請使用獨立於兩個表的序列來生成主鍵值。 否則,您需要進行一些手動處理,例如“ id”表或類似的處理-原子地進行操作可能很棘手。
基本上,如果給我這個問題,我會問為什么兩個表到底需要這樣的唯一主鍵值-如果主鍵是一個自動遞增的整數,則表明它沒有意義。 唯一的目的是在單個表中提供唯一鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.