我正在尝试创建一个表,users
但是在使用 MySQL Workbench 和 PHPMyAdmin 运行查询时出现错误“无法创建表”。我似乎在它说的地方收到错误:
存储 VARCHAR(5),
CREATE TABLE store
(
id INT NOT NULL AUTO_INCREMENT,
short_name VARCHAR(5) NOT NULL,
name VARCHAR(30) NOT NULL,
address1 VARCHAR(50) NOT NULL,
address2 VARCHAR(20),
city VARCHAR(30) NOT NULL,
state VARCHAR(30) NOT NULL,
zip VARCHAR(10) NOT NULL,
phone VARCHAR(15) NOT NULL,
CONSTRAINT store_pk PRIMARY KEY (id)
);
CREATE TABLE users
(
id INT NOT NULL AUTO_INCREMENT,
fname VARCHAR(35) NOT NULL,
lname VARCHAR(35) NOT NULL,
password VARCHAR(60),
address1 VARCHAR(50) NOT NULL,
address2 VARCHAR(20),
city VARCHAR(30) NOT NULL,
state VARCHAR(30) NOT NULL,
zip VARCHAR(10) NOT NULL,
phone VARCHAR(15),
email VARCHAR(90),
store VARCHAR(5),
admin TINYINT DEFAULT 0 NOT NULL,
mail_list TINYINT DEFAULT 0 NOT NULL,
active TINYINT DEFAULT 0 NOT NULL,
CONSTRAINT users_pk PRIMARY KEY (id),
CONSTRAINT users_fk FOREIGN KEY (store)
REFERENCES store (short_name)
ON DELETE SET NULL
ON UPDATE CASCADE
);
存储表添加成功。只有当我尝试创建用户表时,我才会收到错误。