簡體   English   中英

如何在PostgreSQL中修復丟失的PostGIS SRID?

[英]How do I fix missing PostGIS SRIDs in PostgreSQL?

運行我的Rspec測試套件時收到以下錯誤:

PG::InternalError: ERROR:  GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys

我知道我啟用了PostGIS擴展。 我該如何解決?

問題是有些東西從spatial_ref_sys表中刪除了行。

就我而言,問題出在我的spec_helper.rb DatabaseCleaner配置中。 它被配置為刪除/截斷表。

要防止該行為,請更改配置。 對我來說,那是:

config.before(:suite) do
  DatabaseCleaner.strategy = :deletion, {:except => %w[spatial_ref_sys]}
  DatabaseCleaner.clean_with :truncation, {:except => %w[spatial_ref_sys]}
end

現在,您需要重新生成該表中的行。 使用名為spatial_ref_sys.sql的腳本來執行此操作。

我使用Postgres.app,所以運行該腳本的命令是:

/Applications/Postgres.app/Contents/MacOS/bin/psql -d database_name -f /Applications/Postgres.app/Contents/MacOS/share/contrib/postgis-2.0/spatial_ref_sys.sql

您的命令可能略有不同。

運行rake db:test:prepare應該恢復spatial_ref_sys的值。

更新:這在版本1.4.1中得到修復: https//github.com/DatabaseCleaner/database_cleaner/pull/328

database_cleaner 1.4.0版中存在一個錯誤,因此您需要指定表異常的模式:

DatabaseCleaner.strategy = :truncation, { except: ["public.spatial_ref_sys"] }
DatabaseCleaner.clean_with :truncation, { except: ["public.spatial_ref_sys"] }

在1.4.0版中,架構作為表名的一部分返回。 請參閱https://github.com/DatabaseCleaner/database_cleaner/pull/282

這是因為沒有spatial_ref_sys表。 使用以下內容插入此表:

psql -d country -f /usr/share/postgresql/9.3/contrib/postgis-2.1/spatial_ref_sys.

country是數據庫名稱,而/usr/share/.../spatial_ref_sys.sql是存儲文件的路徑。 這適合我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM