Tuesday, 24 December 2024

MYSQL set uuid id, text column cant have default value

 Good old auto increment

CREATE TABLE example (

    id INT AUTO_INCREMENT PRIMARY KEY,

    description TEXT NOT NULL

);

// TEXT column cant have default value ''
// use
CREATE TABLE example (
    id INT AUTO_INCREMENT PRIMARY KEY,
    description TEXT
);

// uuid
CREATE TABLE my_table (
    id CHAR(36) NOT NULL PRIMARY KEY,
    name VARCHAR(255) NOT NULL
);
Insert values manually:

sql
Copy code
INSERT INTO my_table (id, name) VALUES (UUID(), 'Sample Name');

No comments:

Post a Comment