我正在尝试使用2个表创建简单数据库,首先是用户信息,第二个用于上传,因为它是教师的项目,我有一些任务......一个是使用外键。
但我无法弄清楚如何做到这一点,当我用phpMyAdmin做的时候一切正常,但是当我导出它并将它放在我的服务器上时我有一些错误;请帮帮我。
CREATE TABLE IF NOT EXISTS `korisnici` (
`UserID` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(12) COLLATE utf8_bin NOT NULL,
`password` varchar(32) COLLATE utf8_bin NOT NULL,
`email` varchar(32) COLLATE utf8_bin NOT NULL,
`telefon` varchar(16) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`UserID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ROW_FORMAT=COMPACT AUTO_INCREMENT=4;
CREATE TABLE IF NOT EXISTS `slike` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) COLLATE utf8_bin NOT NULL,
`size` int(11) NOT NULL,
`type` varchar(200) COLLATE utf8_bin NOT NULL,
`file_path` varchar(200) COLLATE utf8_bin NOT NULL,
`username` varchar(12) COLLATE utf8_bin NOT NULL,
`naslov` varchar(32) COLLATE utf8_bin NOT NULL,
`adresa` varchar(80) COLLATE utf8_bin NOT NULL,
`opis` varchar(1200) COLLATE utf8_bin NOT NULL,
`datum` date NOT NULL,
`UserID` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `UserID` (`UserID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4 ;
ALTER TABLE `slike`
ADD CONSTRAINT `slike_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `korisnici` (`UserID`);
错误:
第77行的错误1072(42000):表格中不存在关键列'UserID'
如果有人能修复我的代码并解释,我将不胜感激。
编辑新错误:
第42行的错误1054(42S22):“字段列表”中的未知列'UserID'
当我插入一些东西时:
SET FOREIGN_KEY_CHECKS=0;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE IF NOT EXISTS `korisnici` (
`username` varchar(12) COLLATE utf8_bin NOT NULL,
`password` varchar(32) COLLATE utf8_bin NOT NULL,
`email` varchar(32) COLLATE utf8_bin NOT NULL,
`telefon` varchar(16) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
INSERT INTO `korisnici` (`username`, `password`, `email`, `telefon`) VALUES('Aleksa2', 'c4b4d0dea25b6f2f38fef63330ea15c8', 'sss@gmail.com', '0649999999');
INSERT INTO `korisnici` (`username`, `password`, `email`, `telefon`) VALUES('Aleksa123', 'a4b4d0dea25b6f2f38fef63330ea15c8', 'aaaa@gmail.com', '0649999999');
CREATE TABLE IF NOT EXISTS `slike` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(200) COLLATE utf8_bin NOT NULL,
`size` int(11) NOT NULL,
`type` varchar(200) COLLATE utf8_bin NOT NULL,
`file_path` varchar(200) COLLATE utf8_bin NOT NULL,
`username` varchar(12) COLLATE utf8_bin NOT NULL,
`naslov` varchar(32) COLLATE utf8_bin NOT NULL,
`adresa` varchar(80) COLLATE utf8_bin NOT NULL,
`opis` varchar(1200) COLLATE utf8_bin NOT NULL,
`datum` date NOT NULL,
PRIMARY KEY (`id`),
KEY `USERNAME_ID` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ;
INSERT INTO `slike` (`id`, `name`, `size`, `type`, `file_path`, `username`, `naslov`, `adresa`, `opis`, `datum`) VALUES(15, '4eb40ffebd3fbec4b1acf34a4fe8cb2d.png', 43395, 'image/png', 'C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb/images/4eb40ffebd3fbec4b1acf34a4fe8cb2d.png', 'Aleksa123', 'asdasdasd', 'dadasdas', 'Opisite problem u najvise 1200 karaktera.', '2014-09-05');
INSERT INTO `slike` (`id`, `name`, `size`, `type`, `file_path`, `username`, `naslov`, `adresa`, `opis`, `datum`) VALUES(16, '92bc0821619c053c503694666f2717ee.png', 32461, 'image/png', 'C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb/images/92bc0821619c053c503694666f2717ee.png', 'Aleksa123', 'dadasdasdas', 'dadasdasdasdasdas', 'Opisite problem u najvise 12dasdasdasdas00 karaktera.', '2014-09-05');
INSERT INTO `slike` (`id`, `name`, `size`, `type`, `file_path`, `username`, `naslov`, `adresa`, `opis`, `datum`) VALUES(17, '89d0507bf3ed3f492647b7fd2f39047a.png', 162203, 'image/png', 'C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb/images/89d0507bf3ed3f492647b7fd2f39047a.png', 'Aleksa123', '1111111111111a', 'dasdasdasda', 'Opisite problsdasdasdasdasaem u najvise 1200 karaktera.', '2014-09-05');
ALTER TABLE `slike`
ADD CONSTRAINT `slike_ibfk_1` FOREIGN KEY (`username`) REFERENCES `korisnici` (`username`);
SET FOREIGN_KEY_CHECKS=1;