MySQL ERROR 1215 (HY000)的一个情况

create table pcourse(
cno char(9),
cpno char(9),
primary key(cno,cpno),
foreign key(cno) references course(cno),
foreign key(cpno) references course(cno)
);
ERROR 1215 (HY000): Cannot add foreign key constraint



西电数据库上机作业。这个外键就是添不上去。之前student和course因为有中文数据,所以set character_set_server和set character_set_database均=utf8,但建表的时候需要定义后还是需要加上default charset=utf8。所以应该是这样:
create table pcourse(
cno char(9),
cpno char(9),
primary key(cno,cpno),
foreign key(cno) references course(cno),
foreign key(cpno) references course(cno)
) default charset=utf8;
注意defualt前面要有空格才行,不然还是ERROR 1215 (HY000): Cannot add foreign key constraint。

建立表course的时候不需要外键:
create table course(
cno char(9),
cname char(48) not null,
ccredit int,
primary key (cno)
);
Warning | 1265 | Data truncated for column ‘cname‘ at row 1
这个同样设置default charset=utf8就解决了。

原文地址:http://blog.51cto.com/12078224/2112658

时间: 2024-10-10 17:03:18

MySQL ERROR 1215 (HY000)的一个情况的相关文章

mysql执行带外键的sql文件时出现mysql ERROR 1215 (HY000): Cannot add foreign key constraint的解决

ERROR 1215 (HY000): Cannot add foreign key constraint 最近在建表时遇到了这个错误,然后找了下找到了解决办法,记录下: 本来是要建两张表: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 create table department( id int, name varchar(20) ); create table employee( id int primary key auto_increment, name varch

Mac mySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决办法

我的环境:Mac 10.11.6 ,mysql  5.7.14  . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 这个错是链接时报的错,要链接必须启动.修复的时候首先要启动mysql. 首先来了解一下 mysql.sock的作用: Mysql有两种连接方式: (1),TCP/IP (2),socket 对mysql.sock来说,其

Linux中mysql进入命令行报错:MYSQL ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.99.192' (111)

场景:在Linux中安装mysql01和mysql02,通过VIP虚出一个VIP=192.168.99.192,mysql01为主ip为192.168.99.153,mysql02为备机ip为192.168.99.154 此时VIP在mysql01上通过 mysql01上连接VIP :mysql -h 192.168.99.192 -P 3306   结果是可以正常进入mysql命令行: 通过mysql02上远程连接VIP 会在界面上报错:mysql error 2003(HY000):Can'

[mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

From: http://m.blog.csdn.net/blog/langkeziju/13511411 我的MySQL版本为5.6.14版本,是二进制包安装的(虽然是二进制包安装的,但是以下问题同样适用于源码安装包安装的MySQL) 今天在我的测试库上添加一个新用户,报错: [[email protected] ~]$ mysql -uroot -p123456 Warning: Using a password on the command line interface can be in

mysql ERROR 126 (HY000): Incorrect key file for table '/tmp/#sql_1d87_0.MYI'; try to repair it

[[email protected] ~]# df -h 查看是否空间不足 在查看mysql数据目录情况 mysql> show variables like '%dir%'; +-----------------------------------------+------------------------------------+ | Variable_name                           | Value                              |

MYSQL ERROR 1194 (HY000)

操作系统文件限制大小导致 MYSQL ERROR 1194 (HY000): Table is marked as crashed and should be repaired 问题处理 同事反馈应用在执行查询某张表时候报ERROR 1194 (HY000): Table is marked as crashed and should be repaired 错误 mysql> select * from ims_stat_msg_history where module='basic' and

[mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 解决方法

在MySQL数据库中的mysql.user表中使用insert语句添加新用户时,可能会出现以下错误: ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 原因是在my.ini配置文件中有这样一条语句 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 指定了严格模式,为了安全,严格模式禁止通过insert 这种形式直接修改mysql库中的user表进行添加新用户

mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

解决方案如下: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory") 原文地址:https://www.cnblogs.com/youran-he/p/8182280.html

mysql - ERROR 1114 (HY000): The table is full

mysql - ERROR 1114 (HY000): The table is full - Stack Overflowhttps://stackoverflow.com/questions/730579/error-1114-hy000-the-table-is-full df -H 硬盘满了 原文地址:https://www.cnblogs.com/rgqancy/p/10937638.html