当前位置:网站首页>MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
2022-07-01 19:41:00 【Desire and Yu Yu】
mysql An error is reported when adding a foreign key 150
Tips :mysql An error is reported when adding a foreign key , But the type of foreign keys is the same , And this field also exists in another table
Wrong content :Can’t create table ‘demo01.tb_Student’ (errno: 150)
Introduction to foreign key usage :
CONSTRAINT Fk_Class_Student FOREIGN KEY(classId) references tb_class(classId)
CONSTRAINT Constraint name FOREIGN KEY( Foreign key name ) references The table name to be associated with the foreign key ( Field name )
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)
)
Solution :
Tips : Creating tb_Student Add after when 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;
边栏推荐
- GetMessage底层机制分析
- Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
- Analysis of GetMessage underlying mechanism
- 利用win7漏洞进行系统登录密码破解
- win10下使用msys+vs2019编译ffmpeg源码
- 【英语语法】Unit1 冠词、名词、代词和数词
- What must be done in graduation season before going to Shanhai
- 【sql优化】with as 和 临时表的区别
- Wireshark packet analysis TCP, FTP
- Nat penetration of gb28181
猜你喜欢
随机推荐
博途V16 获取系统时间转换成字符串
研究了11种实时聊天软件,我发现都具备这些功能…
Actual combat of flutter - fast implementation of audio and video call application
118. 杨辉三角
采集抖音视频
Simplified pinduoduo product data
类加载机制
Introduction and installation of crunch, and making password dictionary with crunch
Compile ffmpeg source code with msys+vs2019 under win10
703. 数据流中的第 K 大元素
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Basic knowledge of audio coding and decoding
Solidity - contract structure - error - ^0.8.4 NEW
Live HLS protocol
CMU AI PhD 第一年总结
宝,运维100+服务器很头疼怎么办?用行云管家!
Basic use of MySQL
Opencv video quality diagnosis - VIDEO occlusion diagnosis
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
241. Different Ways to Add Parentheses