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 trialMarc Busby
35,550 PointsMake Migrations on the newer version of Django
Just in case anyone else is following along on their local machine and is using a newer version of Django, you will probably get an error when you try and run the migrations suggesting that the Foreign Key requires an additional argument.
Changing the line to:
course = models.ForeignKey(Course, on_delete=models.CASCADE)
Should fix the issue.
Xayaseth Boudsady
21,951 PointsThanks Marc Busby I thought was doing something wrong. This should be included in the Teacher's note.
Taehwa Kang
8,097 PointsThanks a lot! you saved me!
darcyprice
4,442 PointsThanks Marc! :)
Anna Muravyeva
12,162 PointsThis seems to work, too. Does anyone know the difference?
course = models.ForeignKey(Course, on_delete=models.DO_NOTHING)
Jonatan Witoszek
15,384 Points@Anna Muravyeva the difference is that if you set models.CASCADE
, Django will delete every Step entry related to specified Course if that course gets deleted. In contrast models.SET_NULL
will... well, sets the course field to null.
There's more in the Django documentation
Rohan Tinna
3,415 PointsThanks ;)
Ben Hendricks
Python Web Development Techdegree Student 15,217 Pointsmuch appreciated!
Steve Dempster
5,868 PointsSteve Dempster
5,868 PointsWorked! Thanks for sharing, Marc!