2014-05-15 72 views
-1

我的工作與Yiiframwork項目手冊和我有這個表我的數據基地項目#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法

CREATE TABLE IF NOT EXISTS `tbl_annonce` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, 
`idEntreprise` tinyint(3) unsigned NOT NULL, 
`titre` varchar(100) NOT NULL, 
`detailleDiscription` varchar(5000) NOT NULL, 
`categorie` varchar(100) DEFAULT NULL, 
`typePoste` varchar(100) NOT NULL, 
`salaireMin` varchar(80) NOT NULL, 
`salaireMax` varchar(80) NOT NULL, 
`niveauEtude` varchar(80) NOT NULL, 
`niveauExperience` varchar(80) NOT NULL, 
`langue` varchar(50) DEFAULT NULL, 
`poste` varchar(50) NOT NULL, 
`pays` varchar(50) NOT NULL, 
`ville` varchar(50) NOT NULL, 
`adresse` varchar(80) NOT NULL, 
`datePublication` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
`etat` varchar(50) NOT NULL, 
`photo` varchar(255) NULL, 
`nometr` text NOT NULL, 
PRIMARY KEY (`id`), 
CONSTRAINT 'fk_idEntrepriseAnn' FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id)ON DELETE CASCADE ON UPDATE CASCADE 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; 

我收到以下錯誤信息:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''fk_idEntrepriseAnn' FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id) ' at line 22 

這裏是什麼,我有

工作•服務器類型的一些信息:MySQL的•服務器版:32年5月5日 - MySQL社區服務器

•phpMyAdmin:4.0.4.1,最新穩定版本:4.1.7

可以任何一個幫助我PLZ!

回答

0

我認爲這個問題是在你的推杆query.Instead錯單引號「fk_idEntrepriseAnn」請嘗試

`fk_idEntrepriseAnn` 
+0

得益於它完美的作品:) – user3639570

+0

歡迎您 –

0

嘗試在'fk_idEntrepriseAnn' 使用"``"

CREATE TABLE IF NOT EXISTS `tbl_annonce` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, 
`idEntreprise` tinyint(3) unsigned NOT NULL, 
`titre` varchar(100) NOT NULL, 
`detailleDiscription` varchar(5000) NOT NULL, 
`categorie` varchar(100) DEFAULT NULL, 
`typePoste` varchar(100) NOT NULL, 
`salaireMin` varchar(80) NOT NULL, 
`salaireMax` varchar(80) NOT NULL, 
`niveauEtude` varchar(80) NOT NULL, 
`niveauExperience` varchar(80) NOT NULL, 
`langue` varchar(50) DEFAULT NULL, 
`poste` varchar(50) NOT NULL, 
`pays` varchar(50) NOT NULL, 
`ville` varchar(50) NOT NULL, 
`adresse` varchar(80) NOT NULL, 
`datePublication` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
`etat` varchar(50) NOT NULL, 
`photo` varchar(255) NULL, 
`nometr` text NOT NULL, 
PRIMARY KEY (`id`), 
CONSTRAINT `fk_idEntrepriseAnn` FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id)ON DELETE CASCADE ON UPDATE CASCADE 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; 
0

我想你在Stackoverflow中是新的!下一次嘗試自己糾正它!因爲Stackoverflow是更難的問題! 我認爲這是正確的答案試試這個:

CREATE TABLE IF NOT EXISTS `tbl_annonce` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, 
`idEntreprise` tinyint(3) unsigned NOT NULL, 
`titre` varchar(100) NOT NULL, 
`detailleDiscription` varchar(5000) NOT NULL, 
`categorie` varchar(100) DEFAULT NULL, 
`typePoste` varchar(100) NOT NULL, 
`salaireMin` varchar(80) NOT NULL, 
`salaireMax` varchar(80) NOT NULL, 
`niveauEtude` varchar(80) NOT NULL, 
`niveauExperience` varchar(80) NOT NULL, 
`langue` varchar(50) DEFAULT NULL, 
`poste` varchar(50) NOT NULL, 
`pays` varchar(50) NOT NULL, 
`ville` varchar(50) NOT NULL, 
`adresse` varchar(80) NOT NULL, 
`datePublication` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
`etat` varchar(50) NOT NULL, 
`photo` varchar(255) NULL, 
`nometr` text NOT NULL, 
PRIMARY KEY (`id`), 
CONSTRAINT `fk_idEntrepriseAnn` FOREIGN KEY (idEntreprise) REFERENCES tbl_entreprise(id)ON DELETE CASCADE ON UPDATE CASCADE 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; 
+0

是的,我的一個新成員,但我輸入了錯誤的代碼,這不是我的問題,任何方式感謝爲了回答我:) – user3639570

+0

歡迎:) – satyres

相關問題