Search code examples
mysqluuidalter-table

Change the field with UUID_Short failed?


I'm trying to alter current id field in organization table to UUID_SHORT but failed?

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

I don't see any error message?!


Solution

  • I don't think you can set the default value for id like this

    Rather you can create a trigger to do this:

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