久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <small id='5ui3Z'></small><noframes id='5ui3Z'>

  1. <legend id='5ui3Z'><style id='5ui3Z'><dir id='5ui3Z'><q id='5ui3Z'></q></dir></style></legend>

        <bdo id='5ui3Z'></bdo><ul id='5ui3Z'></ul>

      <tfoot id='5ui3Z'></tfoot>

      MySQL 創建帶有外鍵的表給出 errno: 150

      MySQL Creating tables with Foreign Keys giving errno: 150(MySQL 創建帶有外鍵的表給出 errno: 150)
        <tbody id='XhUgg'></tbody>
      <tfoot id='XhUgg'></tfoot>

      <small id='XhUgg'></small><noframes id='XhUgg'>

      <legend id='XhUgg'><style id='XhUgg'><dir id='XhUgg'><q id='XhUgg'></q></dir></style></legend>
        <bdo id='XhUgg'></bdo><ul id='XhUgg'></ul>

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

                本文介紹了MySQL 創建帶有外鍵的表給出 errno: 150的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試在 MySQL 中創建一個帶有兩個外鍵的表,該表引用了其他 2 個表中的主鍵,但是我收到了 errno: 150 錯誤并且它不會創建表.

                I am trying to create a table in MySQL with two foreign keys, which reference the primary keys in 2 other tables, but I am getting an errno: 150 error and it will not create the table.

                這是所有 3 個表的 SQL:

                Here is the SQL for all 3 tables:

                CREATE TABLE role_groups (
                  `role_group_id` int(11) NOT NULL `AUTO_INCREMENT`,
                  `name` varchar(20),
                  `description` varchar(200),
                  PRIMARY KEY (`role_group_id`)
                ) ENGINE=InnoDB;
                
                CREATE TABLE IF NOT EXISTS `roles` (
                  `role_id` int(11) NOT NULL AUTO_INCREMENT,
                  `name` varchar(50),
                  `description` varchar(200),
                  PRIMARY KEY (`role_id`)
                ) ENGINE=InnoDB;
                
                create table role_map (
                  `role_map_id` int not null `auto_increment`,
                  `role_id` int not null,
                  `role_group_id` int not null,
                  primary key(`role_map_id`),
                  foreign key(`role_id`) references roles(`role_id`),
                  foreign key(`role_group_id`) references role_groups(`role_group_id`)
                ) engine=InnoDB;
                

                任何幫助將不勝感激.

                推薦答案

                我在使用 ALTER TABLE ADD FOREIGN KEY 時遇到了同樣的問題.

                I had the same problem with ALTER TABLE ADD FOREIGN KEY.

                一個小時后,我發現必須滿足這些條件才不會出現錯誤 150:

                After an hour, I found that these conditions must be satisfied to not get error 150:

                1. 在定義外鍵以引用它之前,父表必須存在.您必須按正確的順序定義表:首先是父表,然后是子表.如果兩個表相互引用,則必須創建一個沒有 FK 約束的表,然后創建第二個表,然后使用 ALTER TABLE 將 FK 約束添加到第一個表.

                1. The Parent table must exist before you define a foreign key to reference it. You must define the tables in the right order: Parent table first, then the Child table. If both tables references each other, you must create one table without FK constraints, then create the second table, then add the FK constraint to the first table with ALTER TABLE.

                兩個表必須都支持外鍵約束,即ENGINE=InnoDB.其他存儲引擎會默默地忽略外鍵定義,因此它們不會返回錯誤或警告,但不會保存 FK 約束.

                The two tables must both support foreign key constraints, i.e. ENGINE=InnoDB. Other storage engines silently ignore foreign key definitions, so they return no error or warning, but the FK constraint is not saved.

                父表中被引用的列必須是鍵的最左邊的列.如果 Parent 中的鍵是 PRIMARY KEYUNIQUE KEY,則最好.

                The referenced columns in the Parent table must be the left-most columns of a key. Best if the key in the Parent is PRIMARY KEY or UNIQUE KEY.

                FK 定義必須以與 PK 定義相同的順序引用 PK 列.例如,如果 FK REFERENCES Parent(a,b,c) 那么 Parent 的 PK 不得按 (a,c,b) 的順序在列上定義.

                The FK definition must reference the PK column(s) in the same order as the PK definition. For example, if the FK REFERENCES Parent(a,b,c) then the Parent's PK must not be defined on columns in order (a,c,b).

                父表中的 PK 列必須與子表中的 FK 列具有相同的數據類型.例如,如果 Parent 表中的 PK 列是 UNSIGNED,請確保為 Child 表字段中的相應列定義 UNSIGNED.

                The PK column(s) in the Parent table must be the same data type as the FK column(s) in the Child table. For example, if a PK column in the Parent table is UNSIGNED, be sure to define UNSIGNED for the corresponding column in the Child table field.

                例外:字符串的長度可能不同.例如,VARCHAR(10) 可以引用 VARCHAR(20),反之亦然.

                Exception: length of strings may be different. For example, VARCHAR(10) can reference VARCHAR(20) or vice versa.

                任何字符串類型的 FK 列必須與相應的 PK 列具有相同的字符集和排序規則.

                Any string-type FK column(s) must have the same character set and collation as the corresponding PK column(s).

                如果子表中已有數據,則 FK 列中的每個值都必須與父表 PK 列中的值匹配.使用以下查詢進行檢查:

                If there is data already in the Child table, every value in the FK column(s) must match a value in the Parent table PK column(s). Check this with a query like:

                SELECT COUNT(*) FROM Child LEFT OUTER JOIN Parent ON Child.FK = Parent.PK 
                WHERE Parent.PK IS NULL;
                

                這必須返回零 (0) 個不匹配的值.顯然,這個查詢是一個通用的例子;您必須替換您的表名和列名.

                This must return zero (0) unmatched values. Obviously, this query is an generic example; you must substitute your table names and column names.

                父表和子表都不能是 TEMPORARY 表.

                Neither the Parent table nor the Child table can be a TEMPORARY table.

                父表和子表都不能是 PARTITIONED 表.

                Neither the Parent table nor the Child table can be a PARTITIONED table.

                如果您使用 ON DELETE SET NULL 選項聲明 FK,則 FK 列必須可以為空.

                If you declare a FK with the ON DELETE SET NULL option, then the FK column(s) must be nullable.

                如果為外鍵聲明約束名稱,則約束名稱在整個架構中必須是唯一的,而不僅僅是在定義約束的表中.兩個表可能沒有自己的同名約束.

                If you declare a constraint name for a foreign key, the constraint name must be unique in the whole schema, not only in the table in which the constraint is defined. Two tables may not have their own constraint with the same name.

                如果其他表中有任何其他 FK 指向您嘗試為其創建新 FK 的同一字段,并且它們的格式不正確(即不同的排序規則),則需要首先使它們保持一致.這可能是過去更改的結果,其中 SET FOREIGN_KEY_CHECKS = 0; 與錯誤定義的不一致關系一起使用.有關如何識別這些 FK 問題的說明,請參閱下方 @andrewdotn 的回答.

                If there are any other FK's in other tables pointing at the same field you are attempting to create the new FK for, and they are malformed (i.e. different collation), they will need to be made consistent first. This may be a result of past changes where SET FOREIGN_KEY_CHECKS = 0; was utilized with an inconsistent relationship defined by mistake. See @andrewdotn's answer below for instructions on how to identify these problem FK's.

                希望這會有所幫助.

                這篇關于MySQL 創建帶有外鍵的表給出 errno: 150的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
              1. <legend id='ntdP6'><style id='ntdP6'><dir id='ntdP6'><q id='ntdP6'></q></dir></style></legend>

              2. <tfoot id='ntdP6'></tfoot>
                  <tbody id='ntdP6'></tbody>

                    <bdo id='ntdP6'></bdo><ul id='ntdP6'></ul>

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

                          <i id='ntdP6'><tr id='ntdP6'><dt id='ntdP6'><q id='ntdP6'><span id='ntdP6'><b id='ntdP6'><form id='ntdP6'><ins id='ntdP6'></ins><ul id='ntdP6'></ul><sub id='ntdP6'></sub></form><legend id='ntdP6'></legend><bdo id='ntdP6'><pre id='ntdP6'><center id='ntdP6'></center></pre></bdo></b><th id='ntdP6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ntdP6'><tfoot id='ntdP6'></tfoot><dl id='ntdP6'><fieldset id='ntdP6'></fieldset></dl></div>
                          主站蜘蛛池模板: 特黄特色大片免费视频观看 | 国产伦精品一区二区三区照片91 | 中文字幕二区三区 | 日韩精品一区二区三区中文字幕 | 一级国产精品一级国产精品片 | 日韩精品一区二区三区中文在线 | 国产精品成人一区二区三区夜夜夜 | 精品伦精品一区二区三区视频 | 九九热在线免费视频 | 国产在线精品一区二区三区 | 日韩三极 | 久久久久资源 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 久久久久国产精品一区 | 欧美午夜一区二区三区免费大片 | 国产精品欧美一区二区三区不卡 | 黄色在线观看网站 | 欧美日韩国产高清 | 爱爱免费视频 | 午夜免费影视 | 盗摄精品av一区二区三区 | 国产99视频精品免费播放照片 | 久优草 | 91免费观看国产 | 婷婷丁香激情 | 毛片区 | 精品日韩在线 | 亚洲精品视| 免费av直接看 | 久久国产欧美日韩精品 | 国产97碰免费视频 | 国产九一精品 | 国产精品久久久久国产a级 欧美日本韩国一区二区 | 国精品一区二区 | 中文字幕爱爱视频 | 日本欧美在线观看视频 | 精品一区二区三区在线播放 | 91影院在线观看 | a免费视频| 久久国产精品72免费观看 | 在线视频 亚洲 |