Answer the question
In order to leave comments, you need to log in
How to use 'ON DUPLICATE KEY UPDATE' correctly?
Hi all. I ran into a problem:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '43117-series' for key 'titles_tmdb_id_type_unique' SQL:
INSERT INTO titles (title,language,country,updated_at,tmdb_id,type) VALUES (Teen Choice Awards, En, US, 2015-05-01 01:44:14, 43117,series) ON DUPLICATE KEY UPDATE title = values(title), language = values(language), country = values(country), updated_at = values(updated_at), tmdb_id = values(tmdb_id), type = values(type)
CREATE TABLE IF NOT EXISTS `titles` (
`id` bigint(20) unsigned NOT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`type` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'movie',
....
`tmdb_id` bigint(20) unsigned DEFAULT NULL,
....
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`country` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE `titles`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `titles_tmdb_id_type_unique` (`tmdb_id`,`type`);
ALTER TABLE `titles`
MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question