- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有两个表,我想创建一个外键,但我遇到了错误 1215。这是表格。
CREATE TABLE `entities_def` (
`entityid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
`parentid` int(10) unsigned DEFAULT NULL COMMENT 'Parent Entity ID',
`nick` varchar(255) NOT NULL COMMENT 'Entity Nickname',
`esid` int(10) unsigned NOT NULL DEFAULT '1' COMMENT 'Entity State ID',
`rdn` varchar(255) NOT NULL COMMENT 'Entity LDAP Relative Distinguished Name',
`etype` enum('physical','legal','structural','external','access') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'physical' COMMENT 'Entity Type',
`ctime` timestamp NULL DEFAULT NULL COMMENT 'Time of Creation',
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time of Last Modification',
`cby` int(10) unsigned DEFAULT NULL COMMENT 'Created By',
`mby` int(10) unsigned DEFAULT NULL COMMENT 'Last Modified By',
`descr` text COMMENT 'Entity Description',
PRIMARY KEY (`entityid`),
KEY `i_parentid` (`parentid`),
KEY `i_nick` (`nick`),
KEY `i_esid` (`esid`),
KEY `i_cby` (`cby`),
KEY `i_mby` (`mby`),
CONSTRAINT `entities_def_fk_cby` FOREIGN KEY (`cby`) REFERENCES `users` (`uid`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `entities_def_fk_esid` FOREIGN KEY (`esid`) REFERENCES `entities_states` (`esid`) ON UPDATE CASCADE,
CONSTRAINT `entities_def_fk_mby` FOREIGN KEY (`mby`) REFERENCES `users` (`uid`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `entities_def_fk_parentid` FOREIGN KEY (`parentid`) REFERENCES `entities_def` (`entityid`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COMMENT='Entities'
第二个:
CREATE TABLE `userdomains` (
`id` int(32) NOT NULL AUTO_INCREMENT,
`accessuserid` int(10) NOT NULL,
`domainname` char(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Domain Names'
我正在尝试创建一个外键约束,如下所示:
alter table userdomains ADD CONSTRAINT userdomains_fk_accessuserid FOREIGN KEY (accessuserid) REFERENCES entities_def (entityid) ;
但错误并没有消失。
运行SHOW ENGINE INNODB STATUS\G
后我得到了
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
但看起来一切都很好,我引用的是父级的主键,两列的类型和长度都相同……看不出哪里出了问题。
最佳答案
我遇到了这个问题并使用 desc TABLE;
检查我的表。我发现我试图在相同长度的有符号和无符号 int 之间创建 FK 关系(在我的例子中是 bigint(20))。请记住,默认情况下 int 是有符号的,而显式是未签名的。
看来您遇到了同样的问题:
userdomains.accessuserid
定义为 int(10) NOT NULL,
同时
entities_def.entityid
定义为 int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity ID',
这种关系的唯一问题是两个 int(10) 值定义了不同的范围,因此不兼容。
如果我是你,我会将它们都定义为无符号。标准行业最佳实践规定 AUTO_INCREMENTing 主键应始终从零开始。
关于mysql - 错误 1215 (HY000) : Cannot add foreign key constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24554729/
I have a question about adding files in git. I have found multiple stackoverflow questions about
我是 visual studio 的新手,来自 Delphi。 我有一个充满 .cs 文件的目录树(根是\Common)。 我还有一个充满应用程序的目录树(根目录是\Applications) 最后,
这个问题在这里已经有了答案: Array's lookup time complexity vs. how it is stored (4 个答案) Time complexity for java
谁能告诉我这两者有什么区别: ALTER TABLE x1 ADD INDEX(a); ALTER TABLE x1 ADD INDEX(b); 和 ALTER TABLE x1 ADD INDEX(
为什么有时我们使用 getChildren() add() 而其他时候我们直接使用 add() es: https://docs.oracle.com/javafx/2/get_started/for
如何使用 bootstrap css 在输入下方添加跨度?我需要做这样的事情: 最佳答案 是这样的吗? http://jsfiddle.net/swm53ran/205/ 您可以使用纯 CSS 来实现
问题 np.add(X, 2*Y, out=X) 比 np.add(X, Y, out=X); np.add(X, Y, out=X).使用 np.add(X, Y, out=X); 是一种实际做法吗
当我跑 git add --intent-to-add .所有未跟踪的文件将其状态从“未跟踪的文件”( git status -s 显示 ?? )更改为“未暂存以进行提交的更改”( git statu
我不知道 .add 之间有什么区别和 .sink.add ? 例子: StreamController myStreamController = StreamController(); stream
getContentPane().add() 和 add() 的意思一样吗? public class TestFrame extends JFrame{ public TestFrame()
git add . 和 git add * 会完成完全相同的事情吗? 最佳答案 不,不会。 * 是一个 glob 模式,不会匹配以 开头的文件。 例如,假设这是当前目录,我有 2 个新文件要添加 fo
git的分支与合并的两种方法 git add -A和 git add . git add -u在功能上看似很相近,但还是存在一点差别 git add . :他会
git add [--all | -A] 之间有什么区别?和 git add . ? 最佳答案 此答案仅适用于 Git 版本 1.x。对于 Git 版本 2.x,请参阅其他答案。 总结: git ad
我刚刚安装了最新的 Wix v3.7。我创建了一个 VS 2010“Excel 2010 加载项”项目,并在同一个解决方案中创建了一个 Wix“安装项目”。 问题是,当我尝试从 Wix 项目中引用 A
YUI.add 和 YUI().add 有什么区别? 最佳答案 在第一种情况下,您要注册一个模块可以加载到 YUI 沙箱中,在第二种情况下,您要构建一个沙箱,然后进行注册(这是一种非常不典型的用法)。
测试代码时,任何输入到列表中的值在按下“enter”后都会消失。 我对编程和网络开发非常陌生。请具体一点,以便我理解。 function addItem(){ var item = documen
我正在浏览 python 的 dis 包。我尝试了代码以查看它是如何工作的 >>> def get(): ... x=4 ... y=x+3 ............ this lin
我已经对我的文件夹进行了版本控制 git init git add . git commit -m 'Initial commit' 我应该怎么做 git add 对于我在 .? 中创建的每个新文件
当我执行 $ git add * 时,有时我意识到 git 不会将已删除的文件添加到舞台上,如果删除或添加它,我需要手动指示,但我想不通找出 $ git add --all 有什么区别。因此,如果星号
这个问题在这里已经有了答案: Difference between "git add -A" and "git add ." (12 个答案) 关闭 6 年前。 目前,当我想提交并将内容推送到远程
我是一名优秀的程序员,十分优秀!