Genarated Pixelz Genarated Pixelz - 7 months ago 15
SQL Question

SQL Table errors

I have a simple SQL table, I keep getting the error "Duplicate entry '0' for PRIMARY KEY"

My table layout:

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

CREATE TABLE IF NOT EXISTS `chat` (
`chat_index` int(11) NOT NULL DEFAULT '0',
`steamid` int(11) DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`flair` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`avatar` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY (`chat_index`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `chat` (`chat_index`, `steamid`, `name`, `flair`, `avatar`) VALUES
(0, 43434, 'lol', 'developer,admin', 'http');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


The chat index should increase automatically, which gives me an error when I try to enable this option. However, if the chat index is -1, it will be a permanent message which will be at the top of the chat window (This is the SQL for a chat WIP.)

Please fix any formatting errors, wrong char set etc.

Thanks in advance!

So the following example data:

SQL Exaple data

The chat index should continue to increment as long as a 0 index is in place.

Answer

change this

  `chat_index` int(11) NOT NULL DEFAULT '0',

to

  `chat_index` int(11) NOT NULL,