当前位置:网站首页>Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy
Composite key relationships using Sqlalchemy - relationships on composite keys using Sqlalchemy
2022-06-13 00:36:00 【Technology feast】
problem :
I have this simple model of Author - Books and can't find a way to make firstName and lastName a composite key and use it in relation. I have this simple Author - Books Model , But no firstName and lastName The method of becoming a composite key and using it in related cases .Any ideas? Do you have any ideas ?
from sqlalchemy import create_engine, ForeignKey, Column, String, Integerfrom sqlalchemy.orm import relationship, sessionmakerfrom sqlalchemy.ext.declarative import declarative_baseBase = declarative_base()engine = create_engine('mssql://user:[email protected]')engine.echo = Truesession = sessionmaker(engine)()class Author(Base): __tablename__ = 'authors' firstName = Column(String(20), primary_key=True) lastName = Column(String(20), primary_key=True) books = relationship('Book', backref='author')class Book(Base): __tablename__ = 'books' title = Column(String(20), primary_key=True) author_firstName = Column(String(20), ForeignKey('authors.firstName')) author_lastName = Column(String(20), ForeignKey('authors.lastName')) Solution :
Reference resources : https://stackoom.com/en/question/VUKP边栏推荐
- Make the tasks in the scheduled task XXL job flexible
- 1. Google grpc framework source code analysis Hello World
- What are the PMP scores?
- 哲學和文學的區別
- [ciscn2019 North China Day2 web1]hack world --buuctf
- String类中split()方法的使用
- Win10 home vs pro vs enterprise vs enterprise LTSC
- ROS2之OpenCV人脸识别foxy~galactic~humble
- PMP registration conditions, time, cost, new version related information
- 测试平台系列(97) 完善执行case部分
猜你喜欢

也许尘埃落地,我们才能想清楚互联网的本质
![[C] Inverts the binary of a decimal number and outputs it](/img/40/dcbe0aac2d0599189697db1f0080b5.jpg)
[C] Inverts the binary of a decimal number and outputs it

Is the newly graduated college student taking BEC or PMP? PM who wants to transfer to another job in the future

Arduino controls tb6600 driver +42 stepper motor

Explain bio, NiO, AIO in detail

Successfully installed opencv under delphixe

浏览器缓存的执行流程

Transaction creation of btcd transaction process (I)

Cve-2021-24078 vulnerability analysis

阿姨学代码续集:能力吊打大批程序员
随机推荐
Five mock technologies of go
63. 不同路径 II
[ciscn2019 North China Day2 web1]hack world --buuctf
[matlab] matrix operation
Buuctf's babysql[geek challenge 2019]
Another year 1024, happy programmer's Day!
Is the newly graduated college student taking BEC or PMP? PM who wants to transfer to another job in the future
[C] Inverts the binary of a decimal number and outputs it
Blinker FAQs
杂记:intel11代和12代移动版支持原生Thunderbolt4接口,桌面版不支持
Transaction creation of btcd transaction process (I)
Summary of openstack installation problems
Leetcode weekly -- April to May
ROS2之OpenCV人脸识别foxy~galactic~humble
Test platform series (97) perfect the case part
Through MDC, you can easily track your scheduled task log
MAYA建模六
[LeetCode]26. Removes duplicates from a sorted array thirty-three
Penetration test summary
Go implements concurrent non blocking caching
