#H2 database sintax error create primary key default UUID

3 messages · Page 1 of 1 (latest)

forest rivet
#

I'm try using H2 database to gen my database in memory with ID UUID primary key gen but I can't do this.

CREATE TABLE register (
id UUID PRIMARY KEY NOT NULL DEFAULT random_uuid(),
username VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
salt VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

I try this, but not sucess.

id UUID PRIMARY KEY DEFAULT RANDOM_UUID(),

The Error:

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-09-01T07:42:03.585-03:00 ERROR 9636 --- [dev] [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Migration V1__data.sql failed

SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "CREATE TABLE register (\000d\000a id UUID PRIMARY KEY NOT NULL [*]DEFAULT random_uuid(),\000d\000a email VARCHAR(255) NOT NULL UNIQUE,\000d\000a username VARCHAR(100) NOT NULL UNIQUE,\000d\000a password VARCHAR(255) NOT NULL,\000d\000a salt VARCHAR(255) NOT NULL,\000d\000a created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\000d\000a updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\000d\000a)"; expected "CONSTRAINT, COMMENT, UNIQUE, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TABLE register (
id UUID PRIMARY KEY NOT NULL DEFAULT random_uuid(),
username VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
salt VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) [42001-224]

glass oasisBOT
#

This post has been reserved for your question.

Hey @forest rivet! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.