johnburn 6 Report post Posted December 4, 2009 satu lg sy perasan, kl awk tgk struktur db awk, care penggunaan foreign key tu salah. ni sql dump yg awk bg:Code:-- -- Constraints for table `issues`-- ALTER TABLE `issues` ADD CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`id`) REFERENCES `category` (`catid`) ON DELETE CASCADE;kl ikut sql dump yg awk bg tu, foreign key dlm table issues ialah id (yg mne dh disetkan sebagai primary key dan nilainye auto increment). foreign key ni akan merujuk kepada field catid dalam table category. ini bermaksud nilai field id dlm table tu mst ade dlm catid kat table category. sepatutnye, field catid dlm table issues tu awk kne buat sebagai foreign key yg merujuk kpd field catid dlm table category.so, drop blk table issues dan bina blk table tu pkai sql ni:Code:-- phpMyAdmin SQL Dump-- version 3.1.3.1-- http://www.phpmyadmin.net---- Host: localhost-- Generation Time: Dec 04, 2009 at 11:27 PM-- Server version: 5.1.33-- PHP Version: 5.2.9SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";---- Database: `test`---- ------------------------------------------------------------ Table structure for table `issues`--CREATE TABLE IF NOT EXISTS `issues` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `catid` int(11) NOT NULL, `idesc` varchar(255) NOT NULL, `pid` int(11) NOT NULL, `idate` date NOT NULL, `userid` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `catid` (`catid`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;---- Dumping data for table `issues`--INSERT INTO `issues` (`id`, `title`, `catid`, `idesc`, `pid`, `idate`, `userid`) VALUES(2, 'Foreign Key', 1, 'How to create foreign key in MySQL database?', 3, '2009-11-17', 1),(3, 'Online Shopping System', 1, 'Is it possible to drag the items into cart? it means that, users don''t have to click', 2, '2009-11-24', 1);---- Constraints for dumped tables------ Constraints for table `issues`--ALTER TABLE `issues` ADD CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`catid`) REFERENCES `category` (`catid`);rasenye xkn kuar error dh kl awk fix kedua-dua bnde yg sy gtau dlm dua2 reply sy nih. kl dh xde error, ade bnde lg akan sy bgtau kemudian ::icon_biggrin:: Quote Share this post Link to post Share on other sites
jeliey 0 Report post Posted December 7, 2009 ok,nti sy try change..tq sgt2 johnburn and sume yg dah bsusah payah menolong sy...really appreciate it! ::herz:: Quote Share this post Link to post Share on other sites