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
  • НаукаНаука

Комментарии • 41

  • @SsaliJonathan
    @SsaliJonathan  2 года назад +29

    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

  • @tomasbenjaminastrada4040
    @tomasbenjaminastrada4040 Год назад +2

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

  • @vecroun
    @vecroun 2 года назад

    Great video, thank you!

  • @braxtonshaffie
    @braxtonshaffie Год назад

    your explanations are really great , good work !

  • @user-gh7sh4ip3q
    @user-gh7sh4ip3q Год назад

    Thank you so much! Really helped :)

  • @nachiket9857
    @nachiket9857 Год назад

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

  • @emilvulkov
    @emilvulkov Год назад

    Very nice demo!

  • @user-cw7xd6de2l
    @user-cw7xd6de2l 2 года назад

    thx good video~!! it helps a lot :)

  • @Amapramaadhy
    @Amapramaadhy 2 года назад

    Amazing content!

  • @adamsekyanzi9975
    @adamsekyanzi9975 2 года назад

    when i found Jonathan i found a savior big up bro

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      Thanks for watching man. I am glad I helped.

  • @ongayijohnian8787
    @ongayijohnian8787 2 месяца назад

    Thanks a lot mahn, 💯

  • @aruncanra2084
    @aruncanra2084 2 года назад

    You are awesome. Thank you.

  • @bitflop
    @bitflop Год назад

    Thank you! better than the docs!

  • @aldrickdev
    @aldrickdev 2 года назад

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

  • @andrewvelez7068
    @andrewvelez7068 2 года назад +1

    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!

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      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.

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      Please visit
      www.buymeacoffee.com/jod35

  • @mostafaalayesh2803
    @mostafaalayesh2803 Год назад

    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 👌

    • @SsaliJonathan
      @SsaliJonathan  Год назад +1

      That’s exactly what it is. How to Access the related table from another table. Thanks for watching

  • @Fantasia1013
    @Fantasia1013 2 года назад

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

    • @SsaliJonathan
      @SsaliJonathan  2 года назад +1

      I have the VSCode extension that allows this to happens

    • @SsaliJonathan
      @SsaliJonathan  2 года назад +1

      It is called the Python extension. Search it in your extensions and install

    • @tabs_spaces
      @tabs_spaces Год назад

      also instal tabnine extension for smart autocompletion

  • @ruoyamwangi
    @ruoyamwangi Год назад

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

    • @SsaliJonathan
      @SsaliJonathan  Год назад +1

      My microphone. Hadn’t yet figured out audio. Thanks for watching though

    • @ruoyamwangi
      @ruoyamwangi Год назад

      @@SsaliJonathan great content,thanks

  • @francogutierreztamayo475
    @francogutierreztamayo475 Год назад

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

    • @SsaliJonathan
      @SsaliJonathan  Год назад

      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

  • @adamgerber7824
    @adamgerber7824 2 года назад

    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)

    • @SsaliJonathan
      @SsaliJonathan  2 года назад

      same thing. if conn = the db connection string

    • @adamgerber7824
      @adamgerber7824 2 года назад

      @@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