[Django]-Removing Foreign Key

8👍

First (ok, you already noted it in your edit), you have a Many-to-Many relationship.

You can just set delete the user-entry from the Thing.watchlist table. You’ll find many examples on how to work with these in the django documentation here.

In short: You can do my_thing.watchlist.remove(object_to_be_removed).

…and to answer your original question (just in case someone runs into this issue), just set the ForeignKey attribute to None i.e. my_thing.watchlist = None.

👤OBu

Leave a comment