Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Resolvendo o código de erro:1005. Não é possível criar a tabela '' (errno:150) Erro


Criar advertisment tabela com charset padrão como utf8;

latim1 colunas não são equivalentes a utf8 colunas. Portanto, a restrição de chave estrangeira não pode ser formada corretamente. Daí o 1005 (ER_CANT_CREATE_TABLE) erro.

Aqui está meu log do mysql.
mysql> CREATE TABLE `advertisment` (
    ->   `ADVTNO` varchar(35) NOT NULL,
    ->   `ADVTDATE` date NOT NULL,
    ->   `POSTCODE` int(2) NOT NULL,
    ->   `ADVTOPENDATE` date NOT NULL COMMENT 'ADVERTISEMENT OPENING DATE',
    ->   `ADVTCLOSEDATE` date NOT NULL COMMENT 'ADVERTISEMENT CLOSING DATE',
    ->   `EDITCLOSEDATE` date NOT NULL COMMENT 'CLOSING DATE FOR EDITING APPLICATION',
    ->   `LASTREPRINTDATE` date NOT NULL COMMENT 'LAST DATE FOR REPRINTING APPLICATION',
    ->   `FEESCST` int(4) NOT NULL COMMENT 'FEE FOR SC/ST CATEGORY',
    ->   `FEESTAFF` int(4) DEFAULT NULL COMMENT 'FEE FOR STAFF ',
    ->   `FEEOBC` int(4) DEFAULT NULL COMMENT 'FEE FOR OBC CATEGORY',
    ->   `ADVOCATEEXPERIENCE` int(2) DEFAULT NULL,
    ->   PRIMARY KEY (`ADVTNO`,`ADVTDATE`,`POSTCODE`),
    ->   KEY `fk_post` (`POSTCODE`),
    ->   CONSTRAINT `fk_post` FOREIGN KEY (`POSTCODE`) REFERENCES `postmaster` (`POSTCODE`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- <== This little change make it work.
Query OK, 0 rows affected (0.06 sec)

mysql> CREATE TABLE `candidatemain` (
    ->
    ->   `ADVTNO` varchar(35) NOT NULL DEFAULT '',
    ->   `ADVTDATE` date NOT NULL DEFAULT '0000-00-00',
    ->   `POSTCODE` int(2) NOT NULL DEFAULT '0',
    ->   `REGISTRATIONNO` int(6) NOT NULL DEFAULT '0',
    ->   `SALUTATION` varchar(10) NOT NULL,
    ->   `FULLNAME` varchar(90) NOT NULL,
    ->   `SURNAME` varchar(30) DEFAULT NULL,
    ->   `NAME` varchar(30) NOT NULL,
    ->   `LASTNAME` varchar(30) DEFAULT NULL,
    ->   `LASTUPDATEDIP` varchar(20) NOT NULL DEFAULT '',
    ->   `LASTUPDATEDDATE` date DEFAULT NULL,
    ->   `ENTRYDATE` date NOT NULL,
    ->   PRIMARY KEY (`ADVTNO`,`ADVTDATE`,`POSTCODE`,`REGISTRATIONNO`),
    ->   KEY `FK_ADVT` (`ADVTNO`, `ADVTDATE`,`POSTCODE`) ,
    ->   CONSTRAINT `FK_ADVT` FOREIGN KEY (`ADVTNO`, `ADVTDATE`,`POSTCODE`) REFERENCES `advertisment ` (`ADVTNO`, `ADVTDATE`,`POSTCODE`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.12 sec)