【发布时间】:2018-10-01 00:39:03
【问题描述】:
如何在mysql中的json类型列上创建唯一索引?例如,我有带有 slug 属性的翻译列。我需要语言中独一无二的 slug translations column image
CREATE TABLE `posts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`root_id` int(10) unsigned NOT NULL,
`translations` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`published_from` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`published_till` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`display_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`images` longtext COLLATE utf8mb4_unicode_ci,
`deleted_at` timestamp NULL DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `posts_user_id_foreign` (`user_id`),
KEY `posts_root_id_foreign` (`root_id`),
CONSTRAINT `posts_root_id_foreign` FOREIGN KEY (`root_id`) REFERENCES `roots` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `posts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `admins` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
【问题讨论】:
-
提供表结构
SHOW CREATE TABLE [table]更好的示例数据作为 ascii 数据表(不是图像)或提供 sqlfiddle.com 或 db-fiddle.com -
更新了我的问题
标签: mysql json indexing unique