Error creating foreign key in MariaDB

3

When trying to create the toy table, the following error appears:

  

ERROR 1005 (HY000): Can not create table brinquedos . brinquedo   (errno: 150 "Foreign key constraint is incorrectly formed")

Follow 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 it months ago in a college job, but now I'm using MariaDB and giving this error! I do not understand much of the peculiarities of MySQL and MariaDB. In MySQL I used the default InnoDB engine. In the MariaDB documentation the default engine is InnoDB too, so I'm using InnoDB (I think).

I thank you for helping me.

    
asked by anonymous 30.12.2016 / 16:33

1 answer

4

UNSIGNED is missing in brinquedo_categoria_id since in the original table SERIAL was defined, which can not be negative either.

    
30.12.2016 / 17:06