3
When trying to create the toy table, the following error appears:
ERROR 1005 (HY000): Can’t create table
brinquedos
.brinquedo
(Rrno: 150 "Foreign key Constraint is incorrectly Formed")
Follows the code:
CREATE TABLE IF NOT EXISTS categoria (
categoria_id SERIAL,
categoria_nome VARCHAR(80) NOT NULL,
PRIMARY KEY (categoria_id),
UNIQUE INDEX categoria_nome_UNIQUE (categoria_nome ASC));
CREATE TABLE IF NOT EXISTS brinquedo (
brinquedo_id SERIAL,
brinquedo_descricao VARCHAR(180) NULL DEFAULT NULL,
brinquedo_imagem_url VARCHAR(180) NOT NULL,
brinquedo_preco DECIMAL(9,2) NOT NULL,
brinquedo_detalhes VARCHAR(180) NULL DEFAULT NULL,
brinquedo_categoria_id BIGINT NOT NULL,
brinquedo_marca VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (brinquedo_id),
UNIQUE INDEX brinquedo_imagem_url_UNIQUE (brinquedo_imagem_url ASC),
CONSTRAINT fk_brinquedo_categoria
FOREIGN KEY (brinquedo_categoria_id)
REFERENCES categoria (categoria_id)
ON DELETE CASCADE
ON UPDATE CASCADE);
This query worked in mysql, I created months ago in a college job, but now I’m using Mariadb and is giving this error! I don’t know much about the peculiarities of Mysql and Mariadb. In Mysql I used the Innodb default engine. In the Mariadb documentation the default engine is Innodb too, so I’m using Innodb (I think).
From now on I thank those who help me.
SERIAL is from Postgresql
– Williams
It even tested what was answered below by
brinquedo_categoria_id BIGINT
UNSIGNED
NOT NULL
?– Bacco
SERIAL works on Mariadb, the first table is successfully created!
– Patterson Silva
UNSIGNED, it worked!
– Patterson Silva