0

I am getting an error. This is the code

CREATE TABLE IF NOT EXISTS `server_info` (
  `name` varchar(256) DEFAULT NULL DEFAULT '',
  `value` int(11) DEFAULT NULL,
  PRIMARY KEY (`name`),
  KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

The error I am receiving is this:

Error Static analysis:

1 errors were found during analysis.

This option conflicts with "DEFAULT". (near "DEFAULT" at position 79) SQL query.

MySQL documentation:

#1171 - All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

Anyone knows what to change in the code above?

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
devg
  • 1
  • 1

1 Answers1

1

You must use 'not null' for primary keys. At name column, change DEFAULT NULL to NOT NULL.

CREATE TABLE IF NOT EXISTS `server_info` (
  `name` varchar(256) NOT NULL DEFAULT '',
  `value` int(11) DEFAULT NULL,
  PRIMARY KEY (`name`),
  KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  • I wouldn't define a DEFAULT for the primary key column either. – Bill Karwin Sep 01 '20 at 14:55
  • That's not necessary. PRIMARY KEY is already unique. Now that I'm looking at it more closely, the additional `KEY (name)` is not needed, since the PRIMARY KEY implicitly creates an index. Also [I don't recommend using MyISAM](https://stackoverflow.com/questions/20148/myisam-versus-innodb/17706717#17706717). – Bill Karwin Sep 01 '20 at 15:55