简体   繁体   中英

PG::DependentObjectsStillExist: ERROR when using rspec

When i run

$rspec "/any_file"

rspec loads in the schema.rb file to setup the database.

My understanding is that when it comes to this line

create_table "queue_classic_jobs", force: true do |t|; end

Rspec runs a

DROP TABLE "queue_classic_jobs"

command.

It trows this error

PG::DependentObjectsStillExist: ERROR:  cannot drop table queue_classic_jobs because 
other objects depend on it (ActiveRecord::StatementInvalid)
DETAIL:  function lock_head(character varying) depends on type queue_classic_jobs
function lock_head(character varying,integer) depends on type queue_classic_jobs
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
: DROP TABLE "queue_classic_jobs"

It looks to me like I have to make rspec

DROP TABLE "queue_classic_jobs" CASCADE

But how?

Are you running Rails >= 4.1? There's a new feature where ActiveRecord tries to keep your test schema in sync with schema.rb without reloading the entire database. You can read about it here: http://guides.rubyonrails.org/4_1_release_notes.html#railties-notable-changes .

Unfortunately it doesn't work with foreign keys: https://github.com/rails/rails/issues/14708 . You can disable it by adding this line at the end of config/environments/test.rb:

config.active_record.maintain_test_schema = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM