#1005 - 无法创建表“classorganizer.turma” (错误号:150)

发布于 2024-12-29 10:17:46 字数 1874 浏览 0 评论 0原文

我不断收到以下错误:*#1005 - Can't create table 'classorganizer.turma' (errno: 150) (Detalhes...) *

试图创建表 Turma,尽管我'我们已经仔细检查了该类中的所有外键案例。有谁知道出了什么问题吗?

谢谢你!

CREATE TABLE Usuario(
email VARCHAR(50) NOT NULL,
nome VARCHAR(30),
senha INTEGER NOT NULL,
dataCadastro DATE NOT NULL,

CONSTRAINT pkUsu PRIMARY KEY(email),
CONSTRAINT formatoEmail CHECK(email LIKE '%@%.%')
)ENGINE=InnoDB;

CREATE TABLE Professor(
id INTEGER NOT NULL AUTO_INCREMENT,
nome VARCHAR(30) NOT NULL UNIQUE,
ranking INTEGER DEFAULT 3,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_prof PRIMARY KEY (id),
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_rank CHECK(ranking >0 AND ranking<6)
)ENGINE=InnoDB;

CREATE TABLE Materia(
codigo VARCHAR(8) NOT NULL,
nro_turmas INTEGER DEFAULT 0,
nome VARCHAR(20) NOT NULL UNIQUE,
nro_cred_aula INTEGER DEFAULT 0,
nro_cred_trab INTEGER DEFAULT 0,
prioridade INTEGER DEFAULT 3,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_prof PRIMARY KEY (id),
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_prio CHECK(prioridade >0 AND prioridade<6)
)ENGINE=InnoDB;

CREATE TABLE Turma(
nro INTEGER NOT NULL AUTO_INCREMENT,
prioridade INTEGER DEFAULT 3,
materia VARCHAR(8) NOT NULL,
professor INTEGER NOT NULL,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_turma PRIMARY KEY (nro),
CONSTRAINT fk_mat FOREIGN KEY (materia) REFERENCES Materia(codigo) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT fk_prof FOREIGN KEY (professor) REFERENCES Professor(id) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_prio CHECK(prioridade >0 AND prioridade<6)
)ENGINE=InnoDB;

I keep getting the following error: *#1005 - Can't create table 'classorganizer.turma' (errno: 150) (Detalhes...) *

from trying to create the table Turma although I've double checked all the foreign keys cases in that class. Does anyone knows whats wrong?

Thank you!

CREATE TABLE Usuario(
email VARCHAR(50) NOT NULL,
nome VARCHAR(30),
senha INTEGER NOT NULL,
dataCadastro DATE NOT NULL,

CONSTRAINT pkUsu PRIMARY KEY(email),
CONSTRAINT formatoEmail CHECK(email LIKE '%@%.%')
)ENGINE=InnoDB;

CREATE TABLE Professor(
id INTEGER NOT NULL AUTO_INCREMENT,
nome VARCHAR(30) NOT NULL UNIQUE,
ranking INTEGER DEFAULT 3,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_prof PRIMARY KEY (id),
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_rank CHECK(ranking >0 AND ranking<6)
)ENGINE=InnoDB;

CREATE TABLE Materia(
codigo VARCHAR(8) NOT NULL,
nro_turmas INTEGER DEFAULT 0,
nome VARCHAR(20) NOT NULL UNIQUE,
nro_cred_aula INTEGER DEFAULT 0,
nro_cred_trab INTEGER DEFAULT 0,
prioridade INTEGER DEFAULT 3,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_prof PRIMARY KEY (id),
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_prio CHECK(prioridade >0 AND prioridade<6)
)ENGINE=InnoDB;

CREATE TABLE Turma(
nro INTEGER NOT NULL AUTO_INCREMENT,
prioridade INTEGER DEFAULT 3,
materia VARCHAR(8) NOT NULL,
professor INTEGER NOT NULL,
usuario VARCHAR(50) NOT NULL,

CONSTRAINT pk_turma PRIMARY KEY (nro),
CONSTRAINT fk_mat FOREIGN KEY (materia) REFERENCES Materia(codigo) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT fk_prof FOREIGN KEY (professor) REFERENCES Professor(id) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT fk_usu FOREIGN KEY (usuario) REFERENCES Usuario(email) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT limites_prio CHECK(prioridade >0 AND prioridade<6)
)ENGINE=InnoDB;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2025-01-05 10:17:46

有很多错误。

  1. 约束 pk_prof 主键(id)id 列在表 Materia 中不存在。
  2. 约束名称(pk_prof、fk_usu)已在 Professor 表中使用。您已在 MateriaTurma 表中使用了它。
    通过选择唯一的名称来纠正它。最简单的方法是省略名称。 MySQL 处理它。
  3. Turma 表中引用了 Materiacodigo 列,但它不是 *key.*
  4. 教授 Turma 列定义为NOT NULL。但您使用了ON DELETE SET NULL

There are lots of errors.

  1. CONSTRAINT pk_prof PRIMARY KEY (id). id column doesn't exist in table Materia.
  2. Constraint names (pk_prof, fk_usu) are already used in Professor table. You have used it in both Materia and Turma table.
    Correct it by choosing unique names. Easiest way is to omit the name. MySQL handle it.
  3. codigo column of Materia is referenced in Turma table, But its not a *key.*
  4. professor column of Turma is defined to be NOT NULL. But you used ON DELETE SET NULL.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文