MySQL的。继续获取外键约束错误形成错误

时间:2018-05-13 21:42:18

标签: mysql foreign-keys

我需要了解为什么我一直收到此错误

 function line_coding(Data,v,Rb)
    n=length(Data);
    if(n>1)
    if(Data(n)==1 && Data(n-1)==0)
      Data=[Data 0];
      n=n+1;
    end;

    else
    if(Data(n)==1)
  Data=[Data 0];
  n=n+1;

end;
Tb=1/Rb;
Ts=Tb/1200;
t=0:Ts:Tb-Ts;
pulse=[ones(1,length(t)/2) zeros(1,length(t)/2) ];
A0=1;
A01=2;
A11=2;
ph0=0;
ph10=0;
ph11=pi;
f=1000;
ph11=pi;
tsym=0:Ts:2*Tb-Ts;

D0=A0*sin(2*pi*f*t+ph0);
D10=A01*sin(2*pi*f*tsym+ph10);
D11=A11*sin(2*pi*f*tsym+ph11);
clock=[];
Dout=[];
Dout2=[];
%   a=1;
%   b=1;
temp =1 ;
for i=1:1:n
clock=[clock pulse];
end
j=1;
while j<=n
    if(Data(j)==0)
        Dout=[Dout D0];
        j=j+1;
    else
       if(Data(j+1)==1)
           Dout=[Dout D11]
       else 
           Dout=[Dout D10]
       end
       j=j+2
    end

end;


T=0:Ts:n*Tb-Ts;
subplot(2,1,1)
plot(T,clock);
grid on
axis([0 n*Tb-Ts -0.1 1.1 ])
subplot(2,1,2)
plot(T,Dout);
grid on
axis([0 n*Tb-Ts -v-0.1*v v+0.1*v])


end
尝试在下表之间创建外键时

Error Code: 1005. Can't create table `test`.`#sql-2394_1043` (errno: 150 "Foreign key constraint is incorrectly formed")

-

CREATE TABLE `componenti_crafting` (
  `id_componente` varchar(255) CHARACTER SET utf8 NOT NULL,
  `nome_componente` varchar(255) CHARACTER SET utf8 NOT NULL,
  `tipo_crafting_componente` set('tecnico','programmazione','chimico') CHARACTER SET utf8 NOT NULL,
  `tipo_componente` set('parametro_x','parametro_y','parametro_z','struttura','batteria','applicativo','supporto','cerotto','fiala','solido','sostanza') CHARACTER SET utf8 NOT NULL,
  `costo_attuale_componente` int(255) DEFAULT NULL,
  `costo_vecchio_componente` int(255) DEFAULT NULL,
  `fcc_componente` int(11) DEFAULT NULL,
  `valore_param_componente` int(11) DEFAULT NULL,
  `volume_componente` int(11) DEFAULT NULL,
  `energia_componente` int(11) DEFAULT NULL,
  `fattore_legame_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `curativo_primario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `psicotropo_primario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `tossico_primario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `curativo_secondario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `psicotropo_secondario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `tossico_secondario_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `possibilita_dipendeza_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `effetto_sicuro_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `descrizione_componente` text CHARACTER SET utf8,
  `tipo_applicativo_componente` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`id_componente`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

通过此命令:

CREATE TABLE `componenti_acquistati` (
  `id_acquisto` int(11) NOT NULL AUTO_INCREMENT,
  `cliente_acquisto` int(11) NOT NULL,
  `id_componente_acquisto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `importo_acquisto` int(11) NOT NULL,
  `data_acquisto` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id_acquisto`),
  KEY `fk_acquirente_idx` (`cliente_acquisto`),
  KEY `fk_comp_acq_idx` (`id_componente_acquisto`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

我检查了字段类型,排序规则和标志(非空,无符号......等),但两个字段之间的所有内容似乎都匹配。 我错过了什么?

提前谢谢!

1 个答案:

答案 0 :(得分:2)

错误是由于引用和引用列的不同排序规则设置所致。 根据MySQL指南,排序规则必须相同,请参阅https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

要检查所使用的实际类型,请使用

show create table componenti_acquistati;
show create table componenti_crafting ;

要更改引用表上的归类类型,请使用

ALTER TABLE `componenti_acquistati`
    CHANGE COLUMN `id_componente_acquisto` `id_componente_acquisto` VARCHAR(255) NOT NULL COLLATE 'utf8_general_ci'