本文介紹了Liquibase使用Postgis;Geometry&Quot;類(lèi)型創(chuàng)建表格的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我正在編寫(xiě)一個(gè)lisibase腳本來(lái)創(chuàng)建一個(gè)具有Geometry列的表(來(lái)自PostgreSQL DB的PostGis擴(kuò)展)
然而,我無(wú)法讓它工作。我的腳本:
- changeSet:
id: 5-change-set-places
comment: Create places table
author: LongLe
validCheckSum: 1:any
changes:
- sql:
dbms: postgresql
endDelimiter: ;
splitStatements: true
sql: |
CREATE TABLE IF NOT EXISTS "${schema}"."places" (
"id" bigint NOT NULL,
"geom" GEOMETRY(Geometry, 4326) NOT NULL
);
GRANT SELECT, INSERT, UPDATE, DELETE ON "${schema}"."places" TO "${rolename}";
ALTER TABLE "${schema}"."places"
DROP CONSTRAINT IF EXISTS "places_pkey",
ADD CONSTRAINT "places_pkey" PRIMARY KEY ("id");
但是,它失敗了,錯(cuò)誤如下:
ERROR: type "geometry" does not exist
我還提到了liphbase-space擴(kuò)展https://github.com/lonnyj/liquibase-spatial,并編寫(xiě)了等價(jià)的配置:
- changeSet:
id: 5-change-set-places
comment: Create places table
author: LongLe
validCheckSum: 1:any
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
primaryKey: true
primaryKeyName: places_pkey
name: id
type: bigint
- column:
constraints:
nullable: false
name: geom
type: GEOMETRY(Geometry,4326)
tableName: test
但仍失敗,錯(cuò)誤為:
31-03-2021年21:07:31.587[Main]警告
C.M.MS.BLOCK…應(yīng)用液化基礎(chǔ)-
應(yīng)用Liqubase嘗試5時(shí)出錯(cuò):更改集遷移失敗
Classpath:db/changelog/db.changelog-master.yaml::5-change-set-places::LongLe:
原因:iquibase.Exception.DatabaseException:Error:Type&Quot;Geomy&Quot;不存在位置:67[FAILED SQL:CREATE TABLE
測(cè)試方案.位置(id BIGINT非空,geom
幾何圖形(幾何圖形,4326)非空,約束位置_pkey
主鍵(Id))]
但是當(dāng)我從日志中取出SQL以運(yùn)行時(shí):
CREATE TABLE testschema.places (id BIGINT NOT NULL, geom geometry(Geometry, 4326) NOT NULL, CONSTRAINT places_pkey PRIMARY KEY (id))
那么它工作得很好。
我肯定漏掉了一些非常簡(jiǎn)單的東西,但我毫無(wú)頭緒地檢查了一下。誰(shuí)有更好的主意?
推薦答案
確保您已運(yùn)行
CREATE EXTENSION postgis;
然后,模式限定數(shù)據(jù)類(lèi)型。如果擴(kuò)展是在public中創(chuàng)建的,請(qǐng)使用
CREATE TABLE places (geom public.geometry, ...);
這篇關(guān)于Liquibase使用Postgis;Geometry&Quot;類(lèi)型創(chuàng)建表格的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,






