SQLAlchemy | One To Many Relationships

preview_player
Показать описание
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:

SUBSCRIBE:

Please donate to my channel:

GITHUB:

TWITTER:

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
Рекомендации по теме
Комментарии
Автор

Thanks! You explained the difference between backred and back_populates very clearly

tomasbenjaminastrada
Автор

your explanations are really great, good work !

braxtonshaffie
Автор

Many thanks for your tutorials : ) Easily one of the best yt tuts!

nachiket
Автор

when i found Jonathan i found a savior big up bro

adamsekyanzi
Автор

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!

andrewvelez
Автор

Great video, I believe what happened towards the end was that you have created multiple of the same user by accident.

aldrickdev
Автор

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 👌

mostafaalayesh
Автор

hello bro how you have auto complet in vscode for sqlalchemy ?

Fantasia
Автор

i dont know what sounds worse, the quality of my earphones or your microphone😬

ruoyamwangi
Автор

Can't 'backref' have the same name of the table??

francogutierreztamayo
Автор

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)

adamgerber