在运行我的Rspec测试套件时,我收到了以下错误:
PG::InternalError: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys
我知道我启用了PostGIS扩展。我该怎么解决这个问题?
在运行我的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 存在一个bug, 因此需要指定表exceptions 的模式(schema):
DatabaseCleaner.strategy = :truncation, { except: ["public.spatial_ref_sys"] }
DatabaseCleaner.clean_with :truncation, { except: ["public.spatial_ref_sys"] }
在 1.4.0 版本中,模式(schema)作为表名的一部分返回。请参见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
是我的文件存储路径。这对我有效。
/usr/share/postgresql/12/contrib/postgis-2.5/spatial_ref_sys.sql
- Kris
/opt/local/share/postgresql93/contrib/postgis-2.1/spatial_ref_sys.sql
- Seamus Abshererake db:test:prepare
或rake spec
即可修复spacial_ref_sys
表的问题。 - Mikespatial_ref_sys
。 - lessless{:except => %w[spatial_ref_sys]}
。这对于 js 功能测试非常普遍,如config.before(:each, :js => true)
。即使功能测试没有使用 postgis,如果功能测试在其他测试之前运行,则在运行整个测试套件时仍会遇到相同的问题。 - Calvin/Applications/Postgres.app/Contents/Versions/9.4/share/postgresql/contrib/postgis-2.1/
。 - CWitty