If you have created a databasetable and you forgot the foreignkeys, you can simply add it later via altering table.
Add a foreignkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE post | |
ADD FOREIGN KEY (`userid`) | |
REFERENCES user(`id`) | |
ON DELETE CASCADE | |
ON UPDATE CASCADE | |
This key references the userid from users to a tupel in table posts. If a user gets deleted or updated the post will be deleted to0.
Deleting a foreign key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alter table post drop foreign key post_ibfk_1 |
asdasd
Keine Kommentare:
Kommentar veröffentlichen