5人参与 • 2025-12-09 • Mysql
这个错误是mysql中非常常见的外键约束创建失败错误。
错误信息:
1005 - can't create table 'zkac.#sql-1350_1' (errno: 150)
这表示mysql在尝试创建表或添加外键约束时失败了,具体是外键约束创建过程中遇到了问题。
检查方法:
show create table navigation_target_point_info; show create table task_type_info;
ntpi_task_type_name和robot_task_type_name的数据类型完全一致检查方法:
show index from task_type_info where key_name = 'primary' or column_name = 'robot_task_type_name';
解决方案:
-- 如果不是主键或唯一键,需要添加 alter table task_type_info add unique index idx_robot_task_type_name (robot_task_type_name);
检查方法:
show table status like 'navigation_target_point_info'; show table status like 'task_type_info';
解决方案:
-- 转换为innodb引擎 alter table navigation_target_point_info engine=innodb; alter table task_type_info engine=innodb;
检查方法:
-- 查找外键表中有但主键表中没有的值 select distinct ntpi.ntpi_task_type_name from navigation_target_point_info ntpi left join task_type_info tti on ntpi.ntpi_task_type_name = tti.robot_task_type_name where ntpi.ntpi_task_type_name is not null and tti.robot_task_type_name is null;
检查方法:
-- 确认表和列是否存在
select * from information_schema.columns
where table_schema = 'zkac'
and table_name in ('navigation_target_point_info', 'task_type_info')
and column_name in ('ntpi_task_type_name', 'robot_task_type_name');以上就是mysql错误1005(errno: 150)的原因分析与解决方案的详细内容,更多关于mysql错误1005(errno: 150)的资料请关注代码网其它相关文章!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论