无法添加外键约束MySql [英] Cannot add foreign key constraignt MySql

查看:187
本文介绍了无法添加外键约束MySql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为MySQL创建一个数据库。它提出了错误'不能添加外键约束'。我看了其他类似的问题,但无法找出它如何与我的表。请帮助!

解决方案

更新您的条目
entry_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
exam_date DATE NOT NULL,

$ b

 CREATE TABLE IF NOT EXISTS b $ b student_id INT参考students(student_id),
subject_id INT REFERENCES主题(subject_id),
PRIMARY KEY(entry_id)

pre>

I am creating a database in MySQL for school. It has come up with the error 'cannot add foreign key constraint.' I have looked at other similar questions but cannot find out how it relates to my table. Please help!

解决方案

Update your entries table like so:

CREATE TABLE IF NOT EXISTS entries(
entry_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
exam_date DATE NOT NULL,
student_id INT REFERENCES students(student_id),
subject_id INT REFERENCES subjects(subject_id),
PRIMARY KEY(entry_id)
)

这篇关于无法添加外键约束MySql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆