I have tried to create a table in a MySQL database with phpmyadmin.
The problem occurred when I try to execute this following query:
CREATE TABLE users(
account_id INT(20) NOT NULL AUTO_INCREMENT DEFAULT '100001',
PASSWORD INT(20) NOT NULL DEFAULT '0',
NAME VARCHAR(250) NOT NULL DEFAULT '0',
account_type VARCHAR(250) NOT NULL DEFAULT '0',
balance DOUBLE(20) NOT NULL DEFAULT '0',
created_at DATE NOT NULL DEFAULT '0',
PRIMARY KEY(account_id)
) ENGINE = INNODB;
The error says:
MySQL Error: #1067 - Invalid default value for 'account_id'
Please help to fix this thing! I have tried many solutions but none of them seem to work
3
Answers
Remove default from account id.
Use below.
created_at DATE NOT NULL DEFAULT ‘0’,
PRIMARY KEY(account_id)
) ENGINE = INNODB;
Your definition is really confused. For instance:
double
. And probably for integers as well.0
is not an appropriate default value for a date.So, you seem to want something like this:
If you wanna
AUTO_INCREMENT
then you cant set the default valueOr if you need a default value then you have to remove
AUTO_INCREMENT