MySQL 5.1#1005-无法创建表'datacode.foto'(错误:150)错误 [英] MySQL 5.1 #1005 - Can't create table 'datacode.foto' (errno: 150) error
本文介绍了MySQL 5.1#1005-无法创建表'datacode.foto'(错误:150)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是phpMyadmin,MySQL 5.1版本,并且尝试在下面运行此SQL,但是当我在phpmyadin上执行此代码时,出现错误无法创建表'datacode.foto'(errno :150),有人知道我的代码在做什么?
i'm in the phpMyadmin, MySQL 5.1 version, and i'm trying to run this SQL below, but when i exe this code on phpmyadin, it's given the error Can't create table 'datacode.foto' (errno: 150), there's someone that knows what's happing with my code ?
CREATE TABLE IF NOT EXISTS `projeto` (
`proj_id` INT NOT NULL AUTO_INCREMENT ,
`proj_nome` VARCHAR(40) NULL ,
`proje_descr` VARCHAR(700) NULL ,
`proj_oque_fizemos` VARCHAR(200) NULL ,
`proj_url` VARCHAR(250) NULL ,
`proj_descr_url` VARCHAR(250) NULL ,
PRIMARY KEY (`proj_id`) )
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `categoria` (
`cat_id` INT NOT NULL AUTO_INCREMENT ,
`cat_nome` VARCHAR(45) NULL ,
PRIMARY KEY (`cat_id`) )
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `foto` (
`foto_id` INT NOT NULL AUTO_INCREMENT ,
`foto_url` VARCHAR(270) NULL ,
`projeto_proj_id` INT NOT NULL ,
PRIMARY KEY (`foto_id`) ,
INDEX `fk_foto_projeto1_idx` (`projeto_proj_id` ASC) ,
CONSTRAINT `fk_foto_projeto1`
FOREIGN KEY (`projeto_proj_id` )
REFERENCES `mydb`.`projeto` (`proj_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `projeto_por_categoria` (
`projeto_proj_id` INT NOT NULL ,
`categoria_cat_id` INT NOT NULL ,
PRIMARY KEY (`projeto_proj_id`, `categoria_cat_id`) ,
INDEX `fk_projeto_has_categoria_categoria1_idx` (`categoria_cat_id` ASC) ,
INDEX `fk_projeto_has_categoria_projeto_idx` (`projeto_proj_id` ASC) ,
CONSTRAINT `fk_projeto_has_categoria_projeto`
FOREIGN KEY (`projeto_proj_id` )
REFERENCES `mydb`.`projeto` (`proj_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_projeto_has_categoria_categoria1`
FOREIGN KEY (`categoria_cat_id` )
REFERENCES `mydb`.`categoria` (`cat_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
推荐答案
您引用的是mydb
数据库中的表,而您的表实际上位于名为datacode
的数据库中:
You're referencing a table in the mydb
database, whereas your tables are actually in a database called datacode
:
REFERENCES `mydb`.`projeto` (`proj_id` )
^^^^^^^--- change (or remove) this database qualifier
这篇关于MySQL 5.1#1005-无法创建表'datacode.foto'(错误:150)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文