本文介绍了MySQL错误150,无法创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建表时遇到问题,我不明白怎么了. phpMyAdmin在PRIMARY KEY声明旁边设置错误指示符...我不明白为什么这是错误的...

I'm having trouble creating a table and I don't understand what's wrong. phpMyAdmin sets the error indicator next to the PRIMARY KEY declaration... I don't get why this is wrong...

此表是一个子表,它与另一个表具有一对多的标识关系.

This table is a child table, which has a one-to-many identifying relationship with another table.

CREATE TABLE IF NOT EXISTS `ruilen`.`Voorwerpen` (
`voorwerpen_id` INT NOT NULL AUTO_INCREMENT ,
`naam` VARCHAR( 45 ) NOT NULL ,
`beschrijving` VARCHAR( 45 ) NULL ,
`Gebruikers_gebruiker_id` INT NOT NULL ,
PRIMARY KEY ( `voorwerpen_id` , `Gebruikers_gebruiker_id` ) ,
CONSTRAINT `fk_Voorwerpen_Gebruikers1` FOREIGN KEY ( `Gebruikers_gebruiker_id` ) REFERENCES `ruilen`.`Gebruikers` (
`gebruiker_id`
) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE = InnoDB;

MySQL said: Documentation
#1005 - Can't create table 'ruilen.voorwerpen' (errno: 150)

这是关于错误代码的所有文档,我可以找到:链接

this is all the documentation on the error code I can find: Link

图片已删除

CREATE TABLE `gebruikers` (
 `gebruiker_id` int(11) NOT NULL,
 `naam` varchar(45) NOT NULL,
 `straat` varchar(45) NOT NULL,
 `gemeente` varchar(45) NOT NULL,
 `mail` varchar(45) NOT NULL,
 `beschrijving` varchar(45) DEFAULT NULL,
 PRIMARY KEY (`gebruiker_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

推荐答案

检查Gebruikers_gebruiker_idGebruikers.gebruiker_id具有相同的数据类型.

Check that Gebruikers_gebruiker_id and Gebruikers.gebruiker_id have same datatype.

还要检查Gebruikers.gebruiker_idGebruikers中的PRIMARY KEY

更新:

您已定义ON DELETE SET NULL,而您的Gebruikers_gebruiker_id被定义为NOT NULL.

You have ON DELETE SET NULL defined, while your Gebruikers_gebruiker_id is defined as NOT NULL.

修复该问题(更改为ON DELETE CASCADE或仅删除该子句),就可以创建引用.

Fix it (change to ON DELETE CASCADE or just remove the clause) and you'll be able to create the reference.

这篇关于MySQL错误150,无法创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:54