Liquibase und MySql – So generieren Sie automatisch eine ID aus UUID
P粉633733146
P粉633733146 2024-03-27 00:01:32
0
1
458

Ich möchte ein Skript für Liquibase erstellen. Wenn ich in meinem nächsten Skript eine Einfügung mache, möchte ich die ID automatisch über UUID generieren. Ich habe versucht, was ich dort gefunden habe: EDIT: Ich habe eine Antwort verwendet:

<property name="u_id" value="uuid()" dbms="mysql"/>
<changeSet id="1" author="xyz">
    <createTable tableName="persons">
        <column name="id" type="varchar(36)" defaultValueComputed="${u_id}">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="name" type="varchar(50)">
            <constraints nullable="false"/>
        </column>
        <column name="surname" type="varchar(50)">
            <constraints nullable="false"/>
        </column>
        <column name="email" type="varchar(50)">
            <constraints nullable="false" unique="true"/>
        </column>
    </createTable>
</changeSet>
</databaseChangeLog>

Das erste Skript funktioniert gut, die Tabelle wird erstellt, aber wenn ich das zweite Skript hinzufüge:

<changeSet  id="2" author="xyz">
    <insert tableName="persons">
        <column  name="name"  value="name value"/>
        <column  name="surname"  value="surname value"/>
        <column  name="email"  value="email value"/>
    </insert>
</changeSet>

Jetzt ist der Fehler:

org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'liquibase' defined in class path resource [liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: 
Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: 
  Migration failed for change set db/version/V1__create_persons_table.xml::1::xyz:
 Reason: liquibase.exception.DatabaseException: 
 You have an error in your SQL syntax; check the manual that corresponds to your 
 MySQL server version for the right syntax to use near 'uuid() NOT NULL, 
 name VARCHAR(50) NOT NULL, surname VARCHAR(50) NOT NULL' at line 1 [Failed SQL: (1064) CREATE TABLE ticketapidatabase.persons (id VARCHAR(36) DEFAULT uuid() NOT NULL, name VARCHAR(50) NOT NULL, surname VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, CONSTRAINT PK_PERSONS PRIMARY KEY (id), UNIQUE (email))]

P粉633733146
P粉633733146

Antworte allen(1)
P粉741678385

您的 id 列定义应如下所示:


    

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!