【发布时间】:2013-11-30 15:50:44
【问题描述】:
我在运行我的 Rspec 测试套件时收到以下错误:
PG::InternalError: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys
我知道我启用了 PostGIS 扩展。我该如何解决这个问题?
【问题讨论】:
标签: postgresql rspec postgis
我在运行我的 Rspec 测试套件时收到以下错误:
PG::InternalError: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys
我知道我启用了 PostGIS 扩展。我该如何解决这个问题?
【问题讨论】:
标签: postgresql rspec postgis
问题是某些东西从spatial_ref_sys 表中删除了行。
就我而言,问题出在我的DatabaseCleaner 配置中的spec_helper.rb 中。它被配置为删除/截断表。
要防止这种行为,请更改配置。对我来说,那是:
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
您的命令可能略有不同。
【讨论】:
/opt/local/share/postgresql93/contrib/postgis-2.1/spatial_ref_sys.sql
rake db:test:prepare 或 rake spec 来修复 spacial_ref_sys 表。
spatial_ref_sys
{:except => %w[spatial_ref_sys]}。这对于 js 功能测试 IE config.before(:each, :js => true) 来说真的很常见。即使特性测试不使用 postgis,如果他的特性测试在其他测试之前运行,那么在运行整个测试套件时你会遇到同样的问题
/Applications/Postgres.app/Contents/Versions/9.4/share/postgresql/contrib/postgis-2.1/
这是因为没有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
运行rake db:test:prepare 应该会恢复spatial_ref_sys 中的值。
更新:这已在 1.4.1 版中修复:https://github.com/DatabaseCleaner/database_cleaner/pull/328
database_cleaner 1.4.0版本有bug,需要指定表异常的schema:
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
【讨论】: