Define a default value to a double in mysql?

2

I have the following table:

CREATE TABLE IF NOT EXISTS tab_gas_card (
id INT(11) NOT NULL AUTO_INCREMENT,
vehicle_id INT(11) NOT NULL,
folio VARCHAR(8) NOT NULL,
nip VARCHAR(4) NOT NULL,
date date NOT NULL,
cost DOUBLE NOT NULL,
amount DOUBLE DEFAULT 0,
active BIT(1) NOT NULL DEFAULT 0.00,
PRIMARY KEY (id),
CONSTRAINT fk_gas_card_tab_vehicle_id FOREIGN KEY (vehicle_id) 
REFERENCES tab_vehicle (id)
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;

and I want the amount field to default to an initial value of 0, but just as I have my code, it only generates a NULL, how could I solve this?

    
asked by Angel Perez 21.06.2017 в 22:39
source

2 answers

1

You missed the quotes, and add a single quote to 0, like this:

CREATE TABLE IF NOT EXISTS 'tab_gas_card' (
'id' INT(11) NOT NULL AUTO_INCREMENT,
'vehicle_id' INT(11) NOT NULL,
'folio' VARCHAR(8) NOT NULL,
'nip' VARCHAR(4) NOT NULL,
'date' date NOT NULL,
'cost' DOUBLE NOT NULL,
'amount' DOUBLE DEFAULT '0',
'active' BIT(1) NOT NULL DEFAULT '0.00',
PRIMARY KEY ('id'),
CONSTRAINT fk_gas_card_tab_vehicle_id FOREIGN KEY ('vehicle_id') 
REFERENCES tab_vehicle ('id')
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;
    
answered by 21.06.2017 в 23:04
0

Instead of a DOUBLE try with a FLOAT and in its default value add a '0.00', like this:

amount FLOAT(10,2) NOT NULL DEFAULT '0.00',

I hope you serve, greetings.

    
answered by 21.06.2017 в 22:42