Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsDatabase ORM foreign key's
I have put this question in python's category, because I am mainly dealing with databases via Pewee and Django.
A ForeignKeyField stores in a row in a table, a reference to the primary key of a row in another table I believe.
So what happens if the row in the table is deleted, the ForeignKeyField contains a reference to a row that no longer exists?
James
1 Answer
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 PointsI suggest you check ForeignKey.on_delete argument documentation. https://docs.djangoproject.com/en/1.10/ref/models/fields/#arguments There are various options you can choose when an object referenced by Foreign Key is deleted (delete object containing the foreign key, set the value to NULL, set the value to default, etc).