我基本上有两个简单的表,我引用了用户的主键从文章表。引擎设置为innoDB,以及如何在两端看到数据类型int。
我的朋友把相同的表插入到他的数据库中,没有任何错误。如果这件事重要的话,他使用XAMPP,我使用Docker
错误消息:
第25行的错误1005 (HY000):无法创建表CMS.Article (errno: 150“外键约束格式不正确”)
CREATE TABLE IF NOT EXISTS USERS (
id int auto_increment primary key,
username varchar(255) NOT NULL,
password varchar(255) NOT NULL,
role ENUM("user", "admin") NOT NULL
);
CREATE TABLE IF NOT EXISTS Article(
id int auto_increment primary key,
userId int NOT NULL,
title varchar(255) NOT NULL,
date date NOT NULL,
content TEXT NOT NULL,
FOREIGN KEY(userId) REFERENCES users(id)
);如何解决这个意外错误?
https://stackoverflow.com/questions/70748532
复制相似问题