1

I stumbled upon weird behavior in MySQL.

Lets say that I have only one record in table

| id | oib |
|----|-----|
| 1  |  5  |

Field oib is unique.

INSERT INTO `test` (`id`, `oib`) VALUES (NULL, '6')

I get following exception

Duplicate entry '5' for key 'oib_UNIQUE'

And this keeps going on no matter what value I try to save. Anyone have idea what could cause this. I've never seen it.

UPDATE:

Here is CREATE TABLE statement:

    CREATE TABLE IF NOT EXISTS `user` (
  `id` int(25) NOT NULL AUTO_INCREMENT,
  `email` varchar(45) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `first_name` varchar(45) DEFAULT NULL,
  `last_name` varchar(45) DEFAULT NULL,
  `dob` int(25) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `zip` int(6) DEFAULT NULL,
  `oib` int(11) DEFAULT NULL,
  `position` tinyint(4) DEFAULT NULL,
  `role` varchar(45) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `note` mediumtext,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_UNIQUE` (`email`),
  UNIQUE KEY `oib_UNIQUE` (`oib`)
)
2
  • 1
    Without your CREATE TABLE statement, I don't think there's much we can say - not that that will stop us! Commented Nov 26, 2015 at 18:35
  • I added table definition Commented Nov 26, 2015 at 18:39

2 Answers 2

2

You cannot insert null value in id primary key

Sign up to request clarification or add additional context in comments.

1 Comment

@strawberry, that fiddle is not quite working the way you think or pretending it is. It is not putting a null in the pk you know that :)
0

Are you sure your table have one record for oib = '5' ?

You cannot insert null into primary key.

1 Comment

Yes, table has only that record

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.