我对数据库设计相当陌生,但我读到你可以在一个表中有两个外键。出于某种原因,我在尝试在 phpMyAdmin 中运行以下 SQL 时遇到错误。
CREATE TABLE tbl_user
(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(45) NOT NULL,
password VARCHAR(45) NOT NULL,
email VARCHAR(72) NOT NULL,
first_name VARCHAR(45),
last_name VARCHAR(45),
role VARCHAR(20),
UNIQUE(username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE tbl_profile
(
id INTEGER NOT NULL PRIMARY KEY,
attribute VARCHAR(128) NOT NULL,
value VARCHAR(128) NOT NULL,
CONSTRAINT FK_userid FOREIGN KEY (id)
REFERENCES tbl_user (id) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FK_attribute FOREIGN KEY (attribute)
REFERENCES tbl_attribute (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE tbl_attribute
(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(45) NOT NULL,
description TEXT,
data_type VARCHAR(45)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
任何帮助是极大的赞赏!