SQLAlchemy | One To Many Relationships
HTML-код
- Опубликовано: 30 июн 2024
- SQLAlchemy | One To Many Relationships.
In this video, I walk through how to create one to many relationships between two models using SQLAlchemy. One-to-many relationships are one of the most common database relationships. If you want to learn how to use one-to-many relationships using SQLAlchemy, then this video is a great starting point.
I walk through how to create database tables and the different ways to create a relationship between two models.
I also explain how to configure delete behaviour using cascade.
SOURCE CODE:
github.com/jod35/sqlalchemy_o...
SUBSCRIBE:
ruclips.net/user/SsaliJonathan...
Please donate to my channel:
www.buymeacoffee.com/jod35
GITHUB:
github.com/jod35
TWITTER:
/ jod35_
Timestamps
00:00 Introduction
01:17 Configuring the database
01:17 Creating the data models
04:36 Creating the database tables
12:12 Foreign keys
13:19 Creating a relationship with a backref
14:50 Creating the database tables
16:16 Populating the database
24:06 Querying related objects using backref
27:09 Querying related objects using back_populates
28:37 backref vs back_populates
28:44 Configuring delete behaviour
35:55 Wrapping Up - Наука
Here is an updated version with better audio using SQLAlchemy 2.0. You can check it out when done here. Thanks for watching. ruclips.net/video/wvQJzMrKy9E/видео.htmlsi=r0cpXV8dZ1Hf9WYY
Thanks! You explained the difference between backred and back_populates very clearly
Thanks for watching.
Great video, thank you!
your explanations are really great , good work !
I am really glad it helped
Thank you so much! Really helped :)
Many thanks for your tutorials : ) Easily one of the best yt tuts!
Glad it helped
Very nice demo!
Thanks for watching
thx good video~!! it helps a lot :)
Amazing content!
I am glad my video helped.
when i found Jonathan i found a savior big up bro
Thanks for watching man. I am glad I helped.
Thanks a lot mahn, 💯
Welcome
You are awesome. Thank you.
Thanks for watching.
Thank you! better than the docs!
Glad it helped
Great video, I believe what happened towards the end was that you have created multiple of the same user by accident.
Yeah. Thanks for watching
Great content Jonathan, really helpful! Do you have a way to accept donations from the US? I'd love to help you upgrade your microphone!
I really appreciate your support and I am glad my video helped. I would like to discuss this with you via email if you are fine with it.
Please visit
www.buymeacoffee.com/jod35
Thank you, I have understood that `backref` is actually the name of a newly created member variable (that holds the related rows from the second table), inside the class specified for the `relationship`, and at the same time, the result of calling `relationship` is also a member variable (which holds the related rows from the first table).
Am I correct?
Thanks for the video
And good luck in the next videos
Subscribed 👌
That’s exactly what it is. How to Access the related table from another table. Thanks for watching
hello bro how you have auto complet in vscode for sqlalchemy ?
I have the VSCode extension that allows this to happens
It is called the Python extension. Search it in your extensions and install
also instal tabnine extension for smart autocompletion
i dont know what sounds worse, the quality of my earphones or your microphone😬
My microphone. Hadn’t yet figured out audio. Thanks for watching though
@@SsaliJonathan great content,thanks
Can't 'backref' have the same name of the table??
It can have the same name. Depends on what you’re trying to do. I always prefer to use a name that really describes the relationship
If anyone is getting an error AttributeError: 'Connection' object has no attribute '_instantiate_plugins',
You have to replace conn in engine= create_engine(conn, echo=True) with the actual URI so for example Im using Sqlite3 so for me it would be:
engine = create_engine('sqlite:///databasename.db', echo=True)
same thing. if conn = the db connection string
@@SsaliJonathan Thats what i did, but even with setting the URI to conn, and then using "conn" , I was getting this error. Only after using the URI directly did it work