Skip to main content

Timeline for Can't define a foreign key

Current License: CC BY-SA 4.0

13 events
when toggle format what by license comment
Jun 18, 2018 at 7:29 comment added hamidi so i prefer not to use the foreign key and do synchronizations manually.
Jun 18, 2018 at 7:08 comment added Lennart - Slava Ukraini If you really need to use 0 instead of null you need to add a 0 monitor group. Beside you can't use the action defined on the foreign key, you need to update any monitors for the monitor group before you delete it.
Jun 17, 2018 at 23:49 comment added ypercubeᵀᴹ " should set to NULL (identical to 0 for me)" 0 is not identical to NULL in SQL.
Jun 17, 2018 at 23:34 history migrated from serverfault.com (revisions)
Jun 5, 2018 at 7:39 comment added hamidi Besides, I prefer no Id of a row in MonitorGroups table be set to 0. This is what I want.
Jun 5, 2018 at 7:37 comment added hamidi I thought it was clear enough. I need not to add any row to MonitorGroups table at first and define the foreign key in such a situation. Certainly all GroupId's in Monitors table should set to NULL (identical to 0 for me). If a GroupId then will have to set to a value other than 0, it should be picked from MonitorGroup table's Id. That's if a GroupId has no value, it's ok. But if it has a value other than 0, it should exist in MonitorGroups table. But I couldn't define such a foreign key.
Jun 3, 2018 at 13:18 comment added TheHe don't know what you're doing. "0" is a valid value with has to be existent on "MonitorGroups"-Table. NULL just says: no foreign key
Jun 2, 2018 at 14:59 comment added hamidi I added a row in table Groups with Id zero and this resolved the problem. But I need to know how can I avoid this.
Jun 2, 2018 at 14:58 vote accept CommunityBot
Jun 2, 2018 at 13:03 comment added hamidi hmm, see, I need no Id of table MonitorGroups be zero or null. I may allow a row in table Monitors have GroupId of zero, but if assigned another value, it should assign from table MonitorGroups. Is it possible?
Jun 2, 2018 at 12:55 comment added TheHe NULL is not the problem here?
Jun 2, 2018 at 12:31 comment added hamidi yes, you're right. as i said, i need to validate existence of rows in table Monitors with GroupId NULL. I know that some database managers support nullable foreign keys, but I'm not sure whether MySQL does it too and how it does.
Jun 2, 2018 at 12:27 history answered TheHe CC BY-SA 4.0