mysql - 错误号 : 3780 Referencing column '%s' and referenced column '%s' in foreign key constraint '%s' are incompatible

标签 mysql error-code

DROP DATABASE IF EXISTS ProviderPatients;
CREATE DATABASE ProviderPatients;
USE ProviderPatients;

CREATE TABLE IF NOT EXISTS Date_Dim (
    Date_ID  integer not null,
    Date_ date,
    Full_Date_Des varchar(25) not null,
    Day_Of_Week int(11) not null,
    Calender_Year int(11) not null,
    Weekday_Indicator int(11) not null,
    primary key(Date_ID));

CREATE TABLE IF NOT EXISTS Insurer_DIM (
    Insurer_ID  int(11) not null,
    Insurer_Name varchar(25) not null,
    Line_Of_Buissness varchar(25) not null,
    primary key(Insurer_ID));

CREATE TABLE IF NOT EXISTS Member_DIM (
    Member_ID   int(11) not null,
    Member_Name varchar(25) not null,
    Age         int(11) not null,
    Ethnicity   varchar(25) not null,
    Health_Condition varchar(25) not null,
    primary key(Member_ID));

CREATE TABLE IF NOT EXISTS Geography_Dim (
    Geography_ID varchar(25) not null,
    Country     varchar(25) not null,
    State       varchar(10) not null,
    State_Code  int(11) not null,
    County_Code int(11) not null,
    primary key(Geography_ID));

CREATE TABLE Provider_Dim (
    Provider_ID int(11) not null, 
    Provider_Name VARCHAR(45) NOT NULL, 
    Gender Varchar(25) Not Null,
    NPI     Varchar(25) Not Null,
    Credential Varchar(25) Not Null, 
PRIMARY KEY(Provider_ID));

CREATE TABLE Eval_Fact_Table(
Date_ID int(11) not null,
Member_ID int(11) not null,
Provider_ID int(11) not null,
Insurer_ID int(11) not null,
Geography_ID int(11) not null,
Num_Visits int(11) not null,
Eval_Costint int(11) not null,
Eval_Start date not null,
Eval_End date not null, 
FOREIGN KEY (Date_ID) References Date_Dim (Date_Id) on delete restrict,
FOREIGN KEY (Member_ID) References Member_Dim (Member_ID) on delete restrict,
FOREIGN KEY (Geography_ID) References Geography_Dim (Geography_ID) on delete restrict,
FOREIGN KEY (Provider_ID) References Proveider_Dim (Provider_ID) on delete restrict,
FOREIGN KEY (Insurer_ID) References Insurer_Dim (Insurer_ID)on delete restrict);

错误编号:3780;符号:ER_FK_INCOMPATIBLE_COLUMNS; SQLSTATE: HY000

消息:错误代码:3780。在外键约束“eval_fact_table_ibfk_3”中引用列“Geography_ID”和引用列“Geography_ID”不兼容。

最佳答案

错误 Referencing column 'Geography_ID' and referenced column 'Geography_ID' in foreign key constraint 'eval_fact_table_ibfk_3' are incompatible.
很清楚,列不兼容:

CREATE TABLE IF NOT EXISTS Geography_Dim (
    Geography_ID varchar(25) not null,

CREATE TABLE Eval_Fact_Table(
... truncated
    Geography_ID int(11) not null,

使它们具有相同的类型或删除外键约束。

您可以阅读有关外键约束的更多信息 in documentation ,最有趣的部分是

Corresponding columns in the foreign key and the referenced key must have similar data types.



您的情况并非如此:varchar(25)对比 int(11)

关于mysql - 错误号 : 3780 Referencing column '%s' and referenced column '%s' in foreign key constraint '%s' are incompatible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61293224/

相关文章:

mysql - MySQL中两个日期之间的差异

php - 除了随机 ID 检索之外,在表中存储数据的最简单数据库解决方案是什么?

lapack - 寻找 LAPACK/BLAS 错误代码列表

postgresql - PostgreSql 中的自定义错误代码类范围?

ruby-on-rails - 如何在rails中为api定义自定义错误代码

tar - tar 时出现错误代码 141

php - 按 id DESC 排序

mysql - 当我尝试在存储过程中更改表时出现 SQL 错误

mysql - 将 VARCHAR 转换为 DATETIME 时为 NULL

c# - 进程无法访问文件 'XYZ' 的错误代码,因为它正被另一个进程使用