0
I am encountering an error while trying to create a table in my database in Mysql.
I read about this error in other occurrences here in stackoverflow, and it seems that it occurs when you try to use a Mysql keyword where it should not be used, but I don’t think this is happening in my code.
Code:
CREATE TABLE tbl_vendas (
`id` INT UNSIGNED NOT NULL,
`id_produto` INT UNSIGNED NOT NULL,
`id_usuario` INT UNSIGNED NOT NULL,
`email_usuario` VARCHAR(50) NOT NULL,
`data_compra` DATE DEFAULT CURRENT_DATE,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_produto`) REFERENCES tbl_produtos(`id`),
FOREIGN KEY (`id_usuario`) REFERENCES tbl_usuario(`id`)
) ENGINE=INNODB;
Error:
#1064 - You have a syntax error in your SQL next to 'CURRENT_DATE,
PRIMARY KEY (
id
),FOREIGN KEY (
id_produto
) REFERENCE' in row 6
It didn’t work! With the
CURRENT_TIMESTAMP
gives me the error:#1067 - Valor padrão (default) inválido para 'data_compra'
– Francisco
@Francisco Sim was how I was changing. To be
CURRENT_TIMESTAMP
it has to be in a column of theTIMESTAMP
and notDATE
– Isac