<tfoot id='TgpKG'></tfoot>
      <legend id='TgpKG'><style id='TgpKG'><dir id='TgpKG'><q id='TgpKG'></q></dir></style></legend>

      1. <small id='TgpKG'></small><noframes id='TgpKG'>

          <bdo id='TgpKG'></bdo><ul id='TgpKG'></ul>
        <i id='TgpKG'><tr id='TgpKG'><dt id='TgpKG'><q id='TgpKG'><span id='TgpKG'><b id='TgpKG'><form id='TgpKG'><ins id='TgpKG'></ins><ul id='TgpKG'></ul><sub id='TgpKG'></sub></form><legend id='TgpKG'></legend><bdo id='TgpKG'><pre id='TgpKG'><center id='TgpKG'></center></pre></bdo></b><th id='TgpKG'></th></span></q></dt></tr></i><div id='TgpKG'><tfoot id='TgpKG'></tfoot><dl id='TgpKG'><fieldset id='TgpKG'></fieldset></dl></div>

        MySQL 无法创建外键约束

        MySQL cannot create foreign key constraint(MySQL 无法创建外键约束)
      2. <small id='cZ2ZA'></small><noframes id='cZ2ZA'>

          <tbody id='cZ2ZA'></tbody>

          • <bdo id='cZ2ZA'></bdo><ul id='cZ2ZA'></ul>
            1. <tfoot id='cZ2ZA'></tfoot>
                <legend id='cZ2ZA'><style id='cZ2ZA'><dir id='cZ2ZA'><q id='cZ2ZA'></q></dir></style></legend>
                <i id='cZ2ZA'><tr id='cZ2ZA'><dt id='cZ2ZA'><q id='cZ2ZA'><span id='cZ2ZA'><b id='cZ2ZA'><form id='cZ2ZA'><ins id='cZ2ZA'></ins><ul id='cZ2ZA'></ul><sub id='cZ2ZA'></sub></form><legend id='cZ2ZA'></legend><bdo id='cZ2ZA'><pre id='cZ2ZA'><center id='cZ2ZA'></center></pre></bdo></b><th id='cZ2ZA'></th></span></q></dt></tr></i><div id='cZ2ZA'><tfoot id='cZ2ZA'></tfoot><dl id='cZ2ZA'><fieldset id='cZ2ZA'></fieldset></dl></div>

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

                  问题描述

                  我在为 mysql 数据库中的现有表创建外键时遇到一些问题.

                  I'm having some problems creating a foreign key to an existing table in a mysql database.

                  我有表格exp:

                  +-------------+------------------+------+-----+---------+-------+
                  | Field       | Type             | Null | Key | Default | Extra |
                  +-------------+------------------+------+-----+---------+-------+
                  | EID         | varchar(45)      | NO   | PRI | NULL    |       |
                  | Comment     | text             | YES  |     | NULL    |       |
                  | Initials    | varchar(255)     | NO   |     | NULL    |       |
                  | ExpDate     | date             | NO   |     | NULL    |       |
                  | InsertDate  | date             | NO   |     | NULL    |       |
                  | inserted_by | int(11) unsigned | YES  | MUL | NULL    |       |
                  +-------------+------------------+------+-----+---------+-------+
                  

                  并且我不想创建一个名为 sample_df 的新表来引用它,使用以下内容:

                  and I wan't to create a new table called sample_df referencing this, using the following:

                  CREATE TABLE sample_df (
                  df_id mediumint(5) unsigned AUTO_INCREMENT primary key,
                  sample_type mediumint(5) unsigned NOT NULL,
                  df_10 BOOLEAN NOT NULL,
                  df_100 BOOLEAN NOT NULL,
                  df_1000 BOOLEAN NOT NULL,
                  df_above_1000 BOOLEAN NOT NULL,
                  target INT(11) unsigned NOT NULL,
                  assay MEDIUMINT(5) unsigned zerofill NOT NULL,
                  insert_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
                  inserted_by INT(11) unsigned NOT NULL,
                  initials varchar(255),
                  experiment VARCHAR(45),
                  CONSTRAINT FOREIGN KEY (inserted_by) REFERENCES user (iduser),
                  CONSTRAINT FOREIGN KEY (target) REFERENCES protein (PID),
                  CONSTRAINT FOREIGN KEY (sample_type) REFERENCES sample_type (ID),
                  CONSTRAINT FOREIGN KEY (assay) REFERENCES assays (AID),
                  CONSTRAINT FOREIGN KEY (experiment) REFERENCES exp (EID)
                  );
                  

                  但我收到错误:

                  ERROR 1215 (HY000): Cannot add foreign key constraint
                  

                  为了获得更多信息,我做了:

                  To get some more information I did:

                  SHOW ENGINE INNODB STATUSG
                  

                  我从中得到的:

                  FOREIGN KEY (experiment) REFERENCES exp (EID)
                  ):
                  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.
                  

                  对我来说,列类型似乎匹配,因为它们都是 varchar(45).(我也尝试将 experiment 列设置为非空,但这并没有解决它)所以我猜测问题一定是在被引用的表中找不到被引用列作为第一列出现的索引.但我不太确定这意味着什么,或者如何检查/修复它.有没有人有什么建议?第一列是什么意思?

                  To me the column types seem to match, since they are both varchar(45).(I also tried setting the experiment column to not null, but this didn't fix it) So I guess the problem must be that Cannot find an index in the referenced table where the referenced columns appear as the first columns. But I'm not quite sure what this means, or how to check/fix it. Does anyone have any suggestions? And what is meant by first columns?

                  推荐答案

                  只是将其放入可能原因的组合中,当引用表列具有相同的类型"但没有相同的签名时,我遇到了这个问题.

                  Just throwing this into the mix of possible causes, I ran into this when the referencing table column had the same "type" but did not have the same signing.

                  在我的例子中,被引用的表列是 TINYINT UNSIGNED 而我的引用表列是 TINYINT SIGNED.对齐两列解决了这个问题.

                  In my case, the referenced table colum was TINYINT UNSIGNED and my referencing table column was TINYINT SIGNED. Aligning both columns solved the issue.

                  这篇关于MySQL 无法创建外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)

                      <small id='4nDMK'></small><noframes id='4nDMK'>

                        <bdo id='4nDMK'></bdo><ul id='4nDMK'></ul>
                          <tbody id='4nDMK'></tbody>
                        <legend id='4nDMK'><style id='4nDMK'><dir id='4nDMK'><q id='4nDMK'></q></dir></style></legend>

                        • <tfoot id='4nDMK'></tfoot>

                            <i id='4nDMK'><tr id='4nDMK'><dt id='4nDMK'><q id='4nDMK'><span id='4nDMK'><b id='4nDMK'><form id='4nDMK'><ins id='4nDMK'></ins><ul id='4nDMK'></ul><sub id='4nDMK'></sub></form><legend id='4nDMK'></legend><bdo id='4nDMK'><pre id='4nDMK'><center id='4nDMK'></center></pre></bdo></b><th id='4nDMK'></th></span></q></dt></tr></i><div id='4nDMK'><tfoot id='4nDMK'></tfoot><dl id='4nDMK'><fieldset id='4nDMK'></fieldset></dl></div>