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

      <tfoot id='HvsMa'></tfoot>
    1. <small id='HvsMa'></small><noframes id='HvsMa'>

    2. <i id='HvsMa'><tr id='HvsMa'><dt id='HvsMa'><q id='HvsMa'><span id='HvsMa'><b id='HvsMa'><form id='HvsMa'><ins id='HvsMa'></ins><ul id='HvsMa'></ul><sub id='HvsMa'></sub></form><legend id='HvsMa'></legend><bdo id='HvsMa'><pre id='HvsMa'><center id='HvsMa'></center></pre></bdo></b><th id='HvsMa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HvsMa'><tfoot id='HvsMa'></tfoot><dl id='HvsMa'><fieldset id='HvsMa'></fieldset></dl></div>
    3. <legend id='HvsMa'><style id='HvsMa'><dir id='HvsMa'><q id='HvsMa'></q></dir></style></legend>
          <bdo id='HvsMa'></bdo><ul id='HvsMa'></ul>

        MySQL 無法添加外鍵約束

        MySQL Cannot Add Foreign Key Constraint(MySQL 無法添加外鍵約束)
      1. <small id='Yv6Q0'></small><noframes id='Yv6Q0'>

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

                1. <i id='Yv6Q0'><tr id='Yv6Q0'><dt id='Yv6Q0'><q id='Yv6Q0'><span id='Yv6Q0'><b id='Yv6Q0'><form id='Yv6Q0'><ins id='Yv6Q0'></ins><ul id='Yv6Q0'></ul><sub id='Yv6Q0'></sub></form><legend id='Yv6Q0'></legend><bdo id='Yv6Q0'><pre id='Yv6Q0'><center id='Yv6Q0'></center></pre></bdo></b><th id='Yv6Q0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Yv6Q0'><tfoot id='Yv6Q0'></tfoot><dl id='Yv6Q0'><fieldset id='Yv6Q0'></fieldset></dl></div>
                  <tfoot id='Yv6Q0'></tfoot>
                    <tbody id='Yv6Q0'></tbody>
                  本文介紹了MySQL 無法添加外鍵約束的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  所以我試圖將外鍵約束作為項目要求添加到我的數據庫中,它第一次或兩次在不同的表上工作,但是我有兩個表在嘗試添加外鍵時出現錯誤約束.我得到的錯誤信息是:

                  So I'm trying to add Foreign Key constraints to my database as a project requirement and it worked the first time or two on different tables, but I have two tables on which I get an error when trying to add the Foreign Key Constraints. The error message that I get is:

                  ERROR 1215 (HY000): 無法添加外鍵約束

                  ERROR 1215 (HY000): Cannot add foreign key constraint

                  這是我用來創建表的 SQL,兩個有問題的表是 PatientAppointment.

                  This is the SQL I'm using to create the tables, the two offending tables are Patient and Appointment.

                  SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
                  SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=1;
                  SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
                  
                  CREATE SCHEMA IF NOT EXISTS `doctorsoffice` DEFAULT CHARACTER SET utf8 ;
                  USE `doctorsoffice` ;
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`doctor`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`doctor` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`doctor` (
                    `DoctorID` INT(11) NOT NULL AUTO_INCREMENT ,
                    `FName` VARCHAR(20) NULL DEFAULT NULL ,
                    `LName` VARCHAR(20) NULL DEFAULT NULL ,
                    `Gender` VARCHAR(1) NULL DEFAULT NULL ,
                    `Specialty` VARCHAR(40) NOT NULL DEFAULT 'General Practitioner' ,
                    UNIQUE INDEX `DoctorID` (`DoctorID` ASC) ,
                    PRIMARY KEY (`DoctorID`) )
                  ENGINE = InnoDB
                  DEFAULT CHARACTER SET = utf8;
                  
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`medicalhistory`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`medicalhistory` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`medicalhistory` (
                    `MedicalHistoryID` INT(11) NOT NULL AUTO_INCREMENT ,
                    `Allergies` TEXT NULL DEFAULT NULL ,
                    `Medications` TEXT NULL DEFAULT NULL ,
                    `ExistingConditions` TEXT NULL DEFAULT NULL ,
                    `Misc` TEXT NULL DEFAULT NULL ,
                    UNIQUE INDEX `MedicalHistoryID` (`MedicalHistoryID` ASC) ,
                    PRIMARY KEY (`MedicalHistoryID`) )
                  ENGINE = InnoDB
                  DEFAULT CHARACTER SET = utf8;
                  
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`Patient`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`Patient` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`Patient` (
                    `PatientID` INT unsigned NOT NULL AUTO_INCREMENT ,
                    `FName` VARCHAR(30) NULL ,
                    `LName` VARCHAR(45) NULL ,
                    `Gender` CHAR NULL ,
                    `DOB` DATE NULL ,
                    `SSN` DOUBLE NULL ,
                    `MedicalHistory` smallint(5) unsigned NOT NULL,
                    `PrimaryPhysician` smallint(5) unsigned NOT NULL,
                    PRIMARY KEY (`PatientID`) ,
                    UNIQUE INDEX `PatientID_UNIQUE` (`PatientID` ASC) ,
                    CONSTRAINT `FK_MedicalHistory`
                      FOREIGN KEY (`MEdicalHistory` )
                      REFERENCES `doctorsoffice`.`medicalhistory` (`MedicalHistoryID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE,
                    CONSTRAINT `FK_PrimaryPhysician`
                      FOREIGN KEY (`PrimaryPhysician` )
                      REFERENCES `doctorsoffice`.`doctor` (`DoctorID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE)
                  ENGINE = InnoDB;
                  
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`Appointment`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`Appointment` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`Appointment` (
                    `AppointmentID` smallint(5) unsigned NOT NULL AUTO_INCREMENT ,
                    `Date` DATE NULL ,
                    `Time` TIME NULL ,
                    `Patient` smallint(5) unsigned NOT NULL,
                    `Doctor` smallint(5) unsigned NOT NULL,
                    PRIMARY KEY (`AppointmentID`) ,
                    UNIQUE INDEX `AppointmentID_UNIQUE` (`AppointmentID` ASC) ,
                    CONSTRAINT `FK_Patient`
                      FOREIGN KEY (`Patient` )
                      REFERENCES `doctorsoffice`.`Patient` (`PatientID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE,
                    CONSTRAINT `FK_Doctor`
                      FOREIGN KEY (`Doctor` )
                      REFERENCES `doctorsoffice`.`doctor` (`DoctorID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE)
                  ENGINE = InnoDB;
                  
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`InsuranceCompany`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`InsuranceCompany` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`InsuranceCompany` (
                    `InsuranceID` smallint(5) NOT NULL AUTO_INCREMENT ,
                    `Name` VARCHAR(50) NULL ,
                    `Phone` DOUBLE NULL ,
                    PRIMARY KEY (`InsuranceID`) ,
                    UNIQUE INDEX `InsuranceID_UNIQUE` (`InsuranceID` ASC) )
                  ENGINE = InnoDB;
                  
                  
                  -- -----------------------------------------------------
                  -- Table `doctorsoffice`.`PatientInsurance`
                  -- -----------------------------------------------------
                  DROP TABLE IF EXISTS `doctorsoffice`.`PatientInsurance` ;
                  
                  CREATE  TABLE IF NOT EXISTS `doctorsoffice`.`PatientInsurance` (
                    `PolicyHolder` smallint(5) NOT NULL ,
                    `InsuranceCompany` smallint(5) NOT NULL ,
                    `CoPay` INT NOT NULL DEFAULT 5 ,
                    `PolicyNumber` smallint(5) NOT NULL AUTO_INCREMENT ,
                    PRIMARY KEY (`PolicyNumber`) ,
                    UNIQUE INDEX `PolicyNumber_UNIQUE` (`PolicyNumber` ASC) ,
                    CONSTRAINT `FK_PolicyHolder`
                      FOREIGN KEY (`PolicyHolder` )
                      REFERENCES `doctorsoffice`.`Patient` (`PatientID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE,
                    CONSTRAINT `FK_InsuranceCompany`
                      FOREIGN KEY (`InsuranceCompany` )
                      REFERENCES `doctorsoffice`.`InsuranceCompany` (`InsuranceID` )
                      ON DELETE CASCADE
                      ON UPDATE CASCADE)
                  ENGINE = InnoDB;
                  
                  USE `doctorsoffice` ;
                  
                  
                  SET SQL_MODE=@OLD_SQL_MODE;
                  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
                  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
                  

                  推薦答案

                  要查找特定錯誤,請運行:

                  To find the specific error run this:

                  SHOW ENGINE INNODB STATUS;
                  

                  并查看 LATEST FOREIGN KEY ERROR 部分.

                  子列的數據類型必須與父列完全匹配.例如,由于 medicalhistory.MedicalHistoryID 是一個 INTPatient.MedicalHistory 也需要是一個 INT,而不是一個 SMALLINT.

                  The data type for the child column must match the parent column exactly. For example, since medicalhistory.MedicalHistoryID is an INT, Patient.MedicalHistory also needs to be an INT, not a SMALLINT.

                  此外,您應該在運行 DDL 之前運行查詢 set foreign_key_checks=0,這樣您就可以按任意順序創建表,而無需在相關子表之前創建所有父表.

                  Also, you should run the query set foreign_key_checks=0 before running the DDL so you can create the tables in an arbitrary order rather than needing to create all parent tables before the relevant child tables.

                  這篇關于MySQL 無法添加外鍵約束的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Break down a table to pivot in columns (SQL,PYSPARK)(分解表以按列進行透視(SQL、PYSPARK))
                  Dropping MySQL table with SparkSQL(使用 SparkSQL 刪除 MySQL 表)
                  Spark giving Null Pointer Exception while performing jdbc save(Spark在執行jdbc保存時給出空指針異常)
                  execute query on sqlserver using spark sql(使用 spark sql 在 sqlserver 上執行查詢)
                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  Spark SQL/Hive Query Takes Forever With Join(Spark SQL/Hive 查詢永遠需要加入)

                2. <tfoot id='8ic0p'></tfoot>
                  <i id='8ic0p'><tr id='8ic0p'><dt id='8ic0p'><q id='8ic0p'><span id='8ic0p'><b id='8ic0p'><form id='8ic0p'><ins id='8ic0p'></ins><ul id='8ic0p'></ul><sub id='8ic0p'></sub></form><legend id='8ic0p'></legend><bdo id='8ic0p'><pre id='8ic0p'><center id='8ic0p'></center></pre></bdo></b><th id='8ic0p'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8ic0p'><tfoot id='8ic0p'></tfoot><dl id='8ic0p'><fieldset id='8ic0p'></fieldset></dl></div>
                    1. <legend id='8ic0p'><style id='8ic0p'><dir id='8ic0p'><q id='8ic0p'></q></dir></style></legend>
                        <tbody id='8ic0p'></tbody>
                        <bdo id='8ic0p'></bdo><ul id='8ic0p'></ul>

                        <small id='8ic0p'></small><noframes id='8ic0p'>

                          1. 主站蜘蛛池模板: jizz视频 | 美女视频一区二区三区 | 日本三级网站在线 | 国产精品欧美一区二区三区不卡 | 日本一区二区在线视频 | 天天夜碰日日摸日日澡 | 秋霞a级毛片在线看 | 韩国av一区二区 | 9191成人精品久久 | 日韩av成人在线观看 | 一区二区三区在线电影 | 国产午夜精品视频 | 久久大陆 | 日韩成人在线播放 | 美女一级a毛片免费观看97 | 国产剧情久久 | 国产小视频在线 | 伊人久久综合 | 午夜精品久久久久久久久久久久 | 国产成人精品亚洲日本在线观看 | 日韩精品一区二区三区中文在线 | 高清欧美性猛交xxxx黑人猛交 | 国产欧美久久精品 | 一级特黄a大片 | 久久国产精品免费视频 | 日韩欧美国产精品一区二区三区 | 日韩精品一区二区三区中文字幕 | 99国内精品 | 天天色天天 | www网站在线观看 | 中文字幕亚洲精品 | 日本啊v在线| 中文字幕一区二区三区四区 | 国产成人精品免高潮在线观看 | 欧美成人a∨高清免费观看 91伊人 | 国产精品久久久久久久久久久久久久 | 国外成人在线视频网站 | 午夜视频一区二区 | 成人av播放 | 日韩视频在线免费观看 | 成在线人视频免费视频 |