0
I’m creating a database and one of the tables doesn’t want to be created with prayer.
The following error appears:
Error Code: 1068. Multiple Primary key defined
What’s wrong with my code?
CREATE TABLE `controle_ferramentas` (
`requisitante_cpf` int NOT NULL primary key,
`data_hora_emprestimo` datetime DEFAULT NULL,
`data_hora_devolucao` datetime DEFAULT NULL,
`area_producao_cultivo_id` int NOT NULL primary key,
`almoxarifado_id` int NOT NULL primary key,
FOREIGN KEY (`area_producao_cultivo_id`) REFERENCES `area_producao_cultivo` (`id`),
FOREIGN KEY (`almoxarifado_id`) REFERENCES `almoxarifado` (`id`),
FOREIGN KEY (`requisitante_cpf`) REFERENCES `funcionarios` (`cpf`)
);
If you want to define a composite primary key then do not put the PRIMARY KEY attribute in each of the columns but put a separate PRIMARY KEY clause:
PRIMARY KEY (requisitante_cpf, area_producao_cultivo_id, almoxarifado_id)
. You just have to check if it really makes sense for your model.– anonimo