[英]Problem with alter and adding foreign keys in MySQL with phpMyadmin
在为项目创建外键时,我一直遇到一个错误,那就是 phpMyAdmin 在我启动此指令时检测到存在语法错误。
alter table articles add constraint idUsers
foreign key idUsers
references users ('idUsers');
它给出了以下错误。
#1064 - Algo está equivocado en su sintax cerca 'references users ('idUsers')' en la linea 3
它仍然给我一个语法问题。 我将传递整个代码。
drop database if exists blog;
create database if not exists blog;
use blog;
create table if not exists users(
idUsers int not null,
name varchar(45) not null,
password varchar(32) not null,
email varchar(45) not null,
primary key (idUsers)
)ENGINE=InnoDB;
create table if not exists category(
idCategory int not null,
category varchar(45) not null,
primary key (idCategory)
)ENGINE=InnoDB;
create table if not exists articles(
idArticles int not null,
title varchar(45),
content text(255),
time date not null,
primary key (idArticles)
)ENGINE=InnoDB;
alter table articles add constraint fk_idUsers
foreign key idUsers
references blog.users (idUsers);
alter table articles add constraint fk_idCategory
foreign key idCategory
references blog.category (idCategory);
错误信息是...
#1064 - Algo está equivocado en su sintax cerca 'references blog.users (idUsers)' en la linea 3
我已经成功了。 我传递了它应该如何的完整代码。 谢谢大家回答我的问题。
drop database if exists blog;
create database if not exists blog;
use blog;
create table if not exists users(
idUsers int primary key,
name varchar(45) not null,
password varchar(32) not null,
email varchar(45) not null
)ENGINE=InnoDB;
create table if not exists category(
idCategory int primary key,
category varchar(45) not null
)ENGINE=InnoDB;
create table if not exists articles(
idArticles int primary key,
title varchar(45),
content text(255),
id_users int,
id_category int,
time date not null
)ENGINE=InnoDB;
alter table articles add foreign key(id_users)
references blog.users(idUsers);
alter table articles add foreign key(id_category)
references blog.category(idCategory);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.