|
|
SET NULL Doesn't Work
I have this table:
MySQL
CREATE TABLE `users` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`login` VARCHAR(20) NOT NULL,
`password` VARCHAR(20) NOT NULL,
`name` VARCHAR(30) NOT NULL,
`email` VARCHAR(30) NOT NULL,
`icq` INT(9) UNSIGNED DEFAULT NULL,
`personal_stream_id` INT(11) NOT NULL,
`TIME` DATETIME NOT NULL,
`url_name` VARCHAR(30) DEFAULT NULL,
`avatar` VARCHAR(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `login` (`login`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `icq` (`icq`),
CONSTRAINT `users_fk` FOREIGN KEY (`id`) REFERENCES `photos` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=latin1;
The constraint is linking this table:
MySQL
CREATE TABLE `photos` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`user_id` INT(11) DEFAULT NULL,
`streams_id` INT(11) NOT NULL,
`description` TEXT,
`hardware_id` INT(11) DEFAULT NULL,
`ratings_id` INT(11) DEFAULT NULL,
`thread_id` INT(11) DEFAULT NULL,
`url_name` VARCHAR(20) DEFAULT NULL,
`views` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `ratings_id` (`ratings_id`),
KEY `user_id` (`user_id`),
KEY `streams_id` (`streams_id`)
) ENGINE=INNODB DEFAULT CHARSET=latin1;
It works, but as you can see, the constraint ondelete action is set to CASCADE, which is not good - it is bad to delete all photos when the user is deleted, I want the database to set user_id value to NULL using the SET NULL action - PHP frontend should display something like "User deleted" then. But when I try to alter the constraint to SET NULL, EMS SQL Manager I'm using shows a very strange error like "Can't create table '.dfk#sql-8e4_4.frm' (errno: 150)". Similiar error is shown when I try to link unsigned int with not unsigned int.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
|
|
|