fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

10K
active users

Dear lazy #django web, a question:

When using to_field for a foreign key, what happens if the contents of the field on the foreign object is edited? Does it update in both places? Or unlink/break? or refuse to change (constraint)?

@keira_reckons
> what happens if the contents of the field on the foreign object is edited?

Three ways to answer that:

* This falls under the topic of "relational integrity": how (and whether) to ensure both ends of the defined relationship, fulfil the promise when one end is modified.

* The database engine will (or, for some very simple ones, will not) have ways to specify the behaviour, when that field is created on the table.

* The ORM has corresponding options to specify that.

bignose

@keira_reckons

Most Relational DBMSen (, , etc.) have explicit options, when defining a foreign key relationship, to declare what must happen; see "ON DELETE RESTRICT", "ON UPDATE CASCADE", and the like.

ORM `ForeignKey` currently allows specifying the "on delete" referential actions, but not "on update". code.djangoproject.com/ticket/

code.djangoproject.com#21295 (Add on_update support) – Django

@bignose yeah that's why I wasn't sure if updating would be a thing.

I have some time tomorrow to play with it and find out. I was just hoping I could save a little time by asking the hive mind. But they weren't buzzing so much today :)