pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="ou6w8gm" 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="iue2quy" 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="24msg2g" id='ntdP6'><tfoot id='ntdP6'></tfoot><dl id='ntdP6'><fieldset id='ntdP6'></fieldset></dl></div>
                          主站蜘蛛池模板: 翅片管换热器「型号全」_厂家-淄博鑫科环保 | 留学生辅导网-在线课程论文辅导-留学生挂科申诉机构 | 欧洲MV日韩MV国产_人妻无码一区二区三区免费_少妇被 到高潮喷出白浆av_精品少妇自慰到喷水AV网站 | 螺旋绞龙叶片,螺旋输送机厂家,山东螺旋输送机-淄博长江机械制造有限公司 | 西安微信朋友圈广告投放_微信朋友圈推广_西安度娘网络科技有限公司 | 搪瓷搅拌器,搪玻璃搅拌器,搪玻璃冷凝器_厂家-淄博越宏化工设备 | STRO|DTRO-STRO反渗透膜(科普)_碟滤 | 清管器,管道清管器,聚氨酯发泡球,清管球 - 承德嘉拓设备 | 云南成考网_云南成人高考报名网 粤丰硕水性环氧地坪漆-防静电自流平厂家-环保地坪涂料代理 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 无负压供水设备,消防稳压供水设备-淄博创辉供水设备有限公司 | 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 六维力传感器_六分量力传感器_模腔压力传感器-南京数智微传感科技有限公司 | 超声波清洗机_细胞破碎仪_实验室超声仪器_恒温水浴-广东洁盟深那仪器 | 铁素体测量仪/检测仪/铁素体含量测试仪-苏州圣光仪器有限公司 | 无菌实验室规划装修设计-一体化实验室承包-北京洁净净化工程建设施工-北京航天科恩实验室装备工程技术有限公司 | 粒米特测控技术(上海)有限公司-测功机_减速机测试台_电机测试台 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 假肢-假肢价格-假肢厂家-河南假肢-郑州市力康假肢矫形器有限公司 | ★塑料拖链__工程拖链__电缆拖链__钢制拖链 - 【上海闵彬】 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 电磁流量计厂家_涡街流量计厂家_热式气体流量计-青天伟业仪器仪表有限公司 | 广东护栏厂家-广州护栏网厂家-广东省安麦斯交通设施有限公司 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 酒瓶_酒杯_玻璃瓶生产厂家_徐州明政玻璃制品有限公司 | 深圳网站建设-高端企业网站开发-定制网页设计制作公司 | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 进口试验机价格-进口生物材料试验机-西安卡夫曼测控技术有限公司 | 防爆型气象站_农业气象站_校园气象站_农业四情监测系统「山东万象环境科技有限公司」 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 衬氟旋塞阀-卡套旋塞阀-中升阀门首页 | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 山楂片_雪花_迷你山楂片_山楂条饼厂家-青州市丰源食品厂 | 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 |