当前位置:网站首页>mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
2022-07-01 19:40:00 【欲與宇語】
mysql 添加外鍵的時候發現報錯 150
提示:mysql 添加外鍵的時候發現報錯 ,但是自己外鍵的類型是一樣的,並且另外一個錶也存在這個字段
報錯內容:Can’t create table ‘demo01.tb_Student’ (errno: 150)
外鍵用法介紹:
CONSTRAINT Fk_Class_Student FOREIGN KEY(classId) references tb_class(classId)
CONSTRAINT 約束名字 FOREIGN KEY(外鍵名字) references 要外鍵關聯的錶名(字段名)
CREATE TABLE tb_class(
classId int PRIMARY KEY AUTO_Increment,
ClassName varchar(20) not null
);
CREATE TABLE tb_Student(
StudentId int primary key Auto_increment,
StudentName varchar(20),
classId int not NULL,
CONSTRAINT Fk_Class_Student FOREIGN KEY(classId) references tb_class(classId)
)
解决方案:
提示:在創建 tb_Student時後面添加 ENGINE = MYISAM;
CREATE TABLE tb_class(
classId int PRIMARY KEY AUTO_Increment,
ClassName varchar(20) not null
);
CREATE TABLE tb_Student(
StudentId int primary key Auto_increment,
StudentName varchar(20),
classId int not NULL,
CONSTRAINT Fk_Class_Student FOREIGN KEY(classId) references tb_class(classId)
)ENGINE = MYISAM;
边栏推荐
- sql查询去重统计的方法总结
- Extensive reading of the paper [film: visual reasoning with a general condition layer]
- Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
- Salesmartly has some tricks for Facebook chat!
- Go Language Advanced
- Case sharing: basic networking configuration of QinQ
- Collect Tiktok video
- 商业智能BI开发和报表开发有什么本质区别?
- H264编码profile & level控制
- What is the essential difference between Bi development and report development?
猜你喜欢
随机推荐
MFC中如何重绘CListCtrl的表头
Ffmpeg common commands (2)
[info() method in org.slf4j.logger]
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
数字化转型企业成功的关键,用数据创造价值
Botu V16 obtains the system time and converts it into a string
Analysis of GetMessage underlying mechanism
求各种极限的方法
【AI服务器搭建】CUDA环境
如何正确使用Vertx操作Redis(3.9.4带源码分析)
Introduction and installation of crunch, and making password dictionary with crunch
Compile ffmpeg source code with msys+vs2019 under win10
Collation of open source protocols of open source frameworks commonly used in Web Development
GetMessage底层机制分析
线程的并行、并发、生命周期
Interview questions for audio and video positions in Dachang -- today's headline
How to redraw the header of CListCtrl in MFC
web开发常用的开源框架的开源协议整理
DTD建模
axure不显示元件库