[英]MYSQL ADD CONSTRAINT ERROR
I am getting errors for my add constraints. 我的添加约束出现错误。
I am using MYSQL workbench to create the tables 我正在使用MYSQL工作台创建表
Message Error from MYSQL workbench: Error Code: 1064 You have an error in your SQL syntax; 来自MYSQL工作台的消息错误:错误代码:1064您的SQL语法中有错误;请参见表11。 check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD CONSTRAINT
user_contact_ibfk1
FOREIGN KEY( user_id
) REFERENCES `user_ac' at line 1 请检查与您的MySQL服务器版本相对应的手册,以获取在'ADD CONSTRAINT
user_contact_ibfk1
FOREIGN KEY( user_id
)参考'第1行中使用的正确语法的正确语法。
Could this just be a version problem I'm having. 这可能只是我遇到的版本问题。 I'm using 5.2.4.7
我正在使用5.2.4.7
Error: 错误:
22:47:35 ADD CONSTRAINT
user_contact_ibfk_1
FOREIGN KEY (user_id
) REFERENCESuser_account
(user_id
) ON DELETE CASCADE ON UPDATE CASCADE Error Code: 1064. You have an error in your SQL syntax;22:47:35添加约束
user_contact_ibfk_1
FOREIGN KEY(user_id
)参考user_account
(user_id
)ON在更新CASCADE上删除CASCADE错误代码:1064。 check the manual that corresponds to your MySQL server version for the right syntax to use near 'ADD CONSTRAINTuser_contact_ibfk_1
FOREIGN KEY (user_id
) REFERENCES `user_ac' at line 1 0.000 sec检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在“ ADD CONSTRAINT
user_contact_ibfk_1
”附近使用FOREIGN KEY(user_id
)参考`user_ac'在第1行0.000秒
--
-- Table structure for table `user_contact`
--
CREATE TABLE IF NOT EXISTS `user_contact` (
`contact_id` bigint(11) NOT NULL AUTO_INCREMENT,
`user_id` bigint(11) NOT NULL,
`first_name` varchar(25) NOT NULL,
`last_name` varchar(25) NOT NULL,
`email` varchar(50) NOT NULL,
`email_code` varchar(32) NOT NULL,
`cellnumber` decimal(32,0) NOT NULL,
`city` varchar(25) NOT NULL,
`state` varchar(25) NOT NULL,
`country` varchar(25) NOT NULL,
`username` varchar(50) NOT NULL,
PRIMARY KEY (`contact_id`),
UNIQUE KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
-- --------------------------------------------------------
--
-- Table structure for table `user_profile`
--
CREATE TABLE IF NOT EXISTS `user_profile` (
`profile_id` bigint(11) NOT NULL AUTO_INCREMENT,
`user_id` bigint(11) NOT NULL,
`username` varchar(50) NOT NULL,
`about_me` text NOT NULL,
`work_info` varchar(255) NOT NULL,
`education_info` varchar(255) NOT NULL,
`rating` float NOT NULL,
`user_image` varchar(1024) NOT NULL,
`friend_array` text NOT NULL,
`online_status` tinyint(1) NOT NULL,
PRIMARY KEY (`profile_id`),
UNIQUE KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
--
-- Table structure for table `user_account`
--
CREATE TABLE IF NOT EXISTS `user_account` (
`user_id` bigint(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
`type` int(11) NOT NULL,
`online_status` tinyint(1) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
--
-- Constraints for table `user_contact`
--
ALTER TABLE `user_contact`
ADD CONSTRAINT `user_contact_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_account` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `user_profile`
--
ALTER TABLE `user_profile`
ADD CONSTRAINT `user_profile_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_account` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
The only thing I can think of is that FOREIGN KEY name might be taken,try changing it. 我唯一想到的是可能会使用FOREIGN KEY名称,请尝试更改它。
ALTER TABLE `user_contact`
ADD CONSTRAINT `user_contact_ibfk_stuff` FOREIGN KEY (`user_id`) REFERENCES `user_account` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
Run this post the result 运行此结果
SELECT @@SESSION.sql_mode;
Or directly run this: 或直接运行:
SET SESSION SQL_MODE='NO_ENGINE_SUBSTITUTION';
Turns out to be some internal bug with MYSQL workbench. 原来是MYSQL工作台的一些内部错误。 I used phpmyadmin and it worked fine.
我使用phpmyadmin,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.