Error trying to create new MySql table

0

I am encountering an error when trying to create a table in my database in MySql.

I read about this error in other occurrences here in the stackoverflow, and it seems that it occurs when you try to use a MySQL keyword where it should not be used, but I do not think this is occurring 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 'on line 6

    
asked by anonymous 26.07.2017 / 01:18

1 answer

1

The problem is setting the date:

'data_compra' DATE DEFAULT CURRENT_DATE

CURRENT_DATE is not supported as the default value, as documentation indicates:

  

DEFAULT

     

Specifies a default value for a column. With one exception, the   default value must be constant; it can not be a function   expression. This means, for example, that you can not set the default   for a date column to be the value of a function such as NOW () or   CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP   as the default for a TIMESTAMP column. See Section 11.3.5, "Automatic   Initialization and Updating for TIMESTAMP ".

Link to Documentation

The exception to the rule is the CURRENT_TIMESTAMP value as the default value that can be used in a column of type TIMESTAMP , as the documentation indicates.

    
26.07.2017 / 01:36