当前位置:网站首页>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;
边栏推荐
猜你喜欢

118. 杨辉三角

对象的创建

wireshark报文分析tcp,ftp

科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”

Salesmartly has some tricks for Facebook chat!

pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】

How to correctly use vertx to operate redis (3.9.4 with source code analysis)

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会

Summary of SQL query de duplication statistics methods

Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
随机推荐
How to solve the problem of splash screen when the main and sub code streams of easygbs are h.265?
JDBC中如何添加事务
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
Detailed explanation of JUnit unit test framework
MFC中如何重绘CListCtrl的表头
ffmpeg AVFrame 转 cv::Mat
Native JS creates a calendar - supports mouse wheel scrolling to select months - and can be ported to any framework
Collation of open source protocols of open source frameworks commonly used in Web Development
Actual combat of flutter - fast implementation of audio and video call application
[English grammar] Unit1 articles, nouns, pronouns and numerals
【sql优化】with as 和 临时表的区别
Contos 7 搭建sftp之创建用户、用户组以及删除用户
Brpc understanding
Crunch简介、安装,使用Crunch制作密码字典
sql查询去重统计的方法总结
Parallelism, concurrency and life cycle of threads
How to redraw the header of CListCtrl in MFC
IPv4 address, subnet mask, gateway
703. The k-th element in the data flow
Ffmpeg audio related commands