[英]While adding foreign key relation mysql (5.5.29) gives ERROR 1050:
While adding foreign key relation MySQL gives ERROR 1050
: 在添加外键关系时,MySQL给出
ERROR 1050
:
I have 2 tables and trying to give foreign key relation with other, but it gives below error. 我有2个表,并试图给出与其他的外键关系,但是它给出了以下错误。
ERROR 1005: Can't create table 'yellowbikes.#sql-1e8_82' (errno: 121)
错误1005:无法创建表'yellowbikes。#sql-1e8_82'(错误号:121)
SQL Statement: SQL语句:
ALTER TABLE `yellowbikes`.`schedule`
ADD CONSTRAINT `bike_number`
FOREIGN KEY (`bike_number` )
REFERENCES `yellowbikes`.`bike` (`bike_number` )
ON DELETE NO ACTION
ON UPDATE NO ACTION
, ADD INDEX `bike_number_idx` (`bike_number` ASC)
ERROR: Error when running failback script.
错误:运行故障回复脚本时出错。 Details follow.
详细信息如下。
ERROR 1050: Table 'schedule' already exists
错误1050:表格“时间表”已存在
SQL Statement: SQL语句:
CREATE TABLE `schedule` (
`bikeid` int(11) NOT NULL,
`bike_number` varchar(24) NOT NULL,
PRIMARY KEY (`bikeid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Check to ensure they are both the same type. 检查以确保它们都是相同的类型。
Schedule
is having type utf8
. Schedule
的类型为utf8
。 Check whthr yellowbikes
is of type default
?!?! 检查whthr
yellowbikes
是类型的default
?!?! If so, change it to utf8
如果是这样,请将其更改为
utf8
Edit: 编辑:
Also you can check if you MySql DB is MyISAM. 您也可以检查您的MySql DB是否为MyISAM。 If so, chane it to InnoDB because if you need the database to enforce foreign key constraints, or you need the database to handle the changes made by set of DML operations as single unit of work then you would choose InnoDB over MyISAM, since these features are absent from the MyISAM engine.
如果是这样,请将其链接到InnoDB,因为如果您需要数据库来强制执行外键约束,或者您需要数据库将DML操作集所做的更改作为单个工作单元来处理,那么您将选择InnoDB而不是MyISAM,因为这些功能MyISAM引擎中没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.