5 Next Steps for Connecting the “Plants” and “Gardens” tables using SQLAlchemy ORM
My app has two tables, Gardens and Plants. When I started, I did not think to include gardens, rather the app was just for documenting plants. However, I quickly realized the user should be able to both search and view plants as well as having more information about the gardens. As a remnant of the start, all of my plants have a “location” column that is not connected to my gardens. Initially, I was also using SQLAlchemy Core. Here are my next steps:
- Create a “foreign key” for my Plants table that is the “id” in the Gardens table.
- Remove “location” column from the Plants table and instead connect the tables with the “foreign key”.
- When searching for plants, the results display this format:
garden name | location.
Change it so that the “location” references the “foreign key”. - When deleting gardens, ask the user whether they would like to delete the plants with the garden.
- If user does not want to delete the plants, change the plants’ “foreign keys” to 1. This represents a “no garden” location.