evanct Posted August 14, 2009 Share Posted August 14, 2009 i want to set it so this particular field in a table automatically takes the value of an auto_increment field. i can't set more than one auto_increment field in a table, and I tried linking the two fields via foreign key but then I get this error: "Cannot add or update a child row: a foreign key constraint fails" how can I do this? Link to comment https://forums.phpfreaks.com/topic/170217-solved-sync-values-of-two-mysql-fields/ Share on other sites More sharing options...
tivrfoa Posted August 14, 2009 Share Posted August 14, 2009 MySQL Coding Help xD use this comand for the tables you're having trouble and post here: show create table table_name; Link to comment https://forums.phpfreaks.com/topic/170217-solved-sync-values-of-two-mysql-fields/#findComment-897899 Share on other sites More sharing options...
evanct Posted August 14, 2009 Author Share Posted August 14, 2009 I would post in the mySQL board... except that it moves at the speed of molasses on a november day CREATE TABLE `posts` ( `post_id` int(11) NOT NULL AUTO_INCREMENT, `post_text` text NOT NULL, `votes` int(11) DEFAULT NULL, `parent` int(11) DEFAULT '0', `children` int(11) DEFAULT '0', `auth_ip` varchar(40) NOT NULL, `auth_name` varchar(40) DEFAULT 'Anonymous', `status` varchar(20) DEFAULT NULL, `thread_parent` int(11) DEFAULT NULL, PRIMARY KEY (`post_id`), KEY `thread_parent` (`thread_parent`), CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`thread_parent`) REFERENCES `posts` (`post_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 If it matters, there is a field in another table that's also linked to post_id. Link to comment https://forums.phpfreaks.com/topic/170217-solved-sync-values-of-two-mysql-fields/#findComment-897905 Share on other sites More sharing options...
tivrfoa Posted August 14, 2009 Share Posted August 14, 2009 foreign key is used to reference columns in other tables, not in the same. do you want that 'thread_parent' be auto_increment too? if yes, then you don't need this column, because it would have the same value as the 'post_id' column. explain what do you want. Link to comment https://forums.phpfreaks.com/topic/170217-solved-sync-values-of-two-mysql-fields/#findComment-897910 Share on other sites More sharing options...
evanct Posted August 14, 2009 Author Share Posted August 14, 2009 Nevermind, i figured out a way to do what I want to do with the php code itself Link to comment https://forums.phpfreaks.com/topic/170217-solved-sync-values-of-two-mysql-fields/#findComment-897914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.