首页 > 解决方案 > 使用 UUID_Short 更改字段失败?

问题描述

我正在尝试将表中的当前id字段更改organization为 UUID_SHORT 但失败了?

ALTER TABLE `organization` CHANGE `id` `id` BIGINT(16) UNSIGNED 
 NOT NULL DEFAULT uuid_short();

我没有看到任何错误信息?!

标签: mysqluuidalter-table

解决方案


我认为您不能id像这样设置默认值

相反,您可以创建一个触发器来执行此操作:

CREATE TRIGGER before_insert_organization
  BEFORE INSERT ON organization 
  FOR EACH ROW
  SET new.id = uuid_short();

推荐阅读