# Tombstone directory not getting cleaned up for images

**URL:** <https://meta.discourse.org/t/tombstone-directory-not-getting-cleaned-up-for-images/106575>\
**Category:** Product Support\
**Created:** [1월 15, 2019, 10:42오전 UTC](https://meta.discourse.org/t/tombstone-directory-not-getting-cleaned-up-for-images/106575 "2019-01-15T10:42:52Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)\
**Post date:** [2월 25, 2020, 11:25오후 UTC](https://meta.discourse.org/t/tombstone-directory-not-getting-cleaned-up-for-images/106575/16 "2020-02-25T23:25:10Z")

</div>

/logs에서 다음과 같은 오류가 발생하여 Jobs::CleanUpUploads가 실패합니다.

```
Job exception: PG::ForeignKeyViolation: ERROR: update or delete on table "uploads" violates foreign key constraint "fk_rails_1d362f2e97" on table "user_profiles"
DETAIL: Key (id)=(169100) is still referenced from table "user_profiles".

```

즉, 디스크에서는 삭제되었지만 데이터베이스에는 여전히 존재하는 업로드가 있는 것으로 보입니다. 데이터베이스에 수동으로 변경 사항을 추가한 적이 100% 없으므로, 이는 버전 마이그레이션 과정에서 생긴 부산물일 것입니다.

콘솔에서 수동으로 수정해야 하는지, 아니면 패키지 내에 사용할 수 있는 스크립트를 추천해 주실 수 있는지 여쭤봐도 될까요?

> **Backtrace**
>
> ```
> rack-mini-profiler-1.1.6/lib/patches/db/pg.rb:69:in `exec_params'
> rack-mini-profiler-1.1.6/lib/patches/db/pg.rb:69:in `exec_params'
> activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:672:in `block (2 levels) in exec_no_cache'
> activesupport-6.0.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
> activesupport-6.0.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
> activesupport-6.0.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
> activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `block in exec_no_cache'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log'
> /usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log'
> activesupport-6.0.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log'
> activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:670:in `exec_no_cache'
> activerecord-6.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `execute_and_clear'
> activerecord-6.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:111:in `exec_delete'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:180:in `delete'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:22:in `delete'
> activerecord-6.0.1/lib/active_record/persistence.rb:395:in `_delete_record'
> activerecord-6.0.1/lib/active_record/persistence.rb:883:in `_delete_row'
> activerecord-6.0.1/lib/active_record/persistence.rb:879:in `destroy_row'
> activerecord-6.0.1/lib/active_record/counter_cache.rb:173:in `destroy_row'
> activerecord-6.0.1/lib/active_record/locking/optimistic.rb:108:in `destroy_row'
> activerecord-6.0.1/lib/active_record/persistence.rb:535:in `destroy'
> activerecord-6.0.1/lib/active_record/callbacks.rb:309:in `block in destroy'
> activesupport-6.0.1/lib/active_support/callbacks.rb:135:in `run_callbacks'
> activesupport-6.0.1/lib/active_support/callbacks.rb:827:in `_run_destroy_callbacks'
> activerecord-6.0.1/lib/active_record/callbacks.rb:309:in `destroy'
> activerecord-6.0.1/lib/active_record/transactions.rb:311:in `block in destroy'
> activerecord-6.0.1/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:279:in `transaction'
> activerecord-6.0.1/lib/active_record/transactions.rb:212:in `transaction'
> activerecord-6.0.1/lib/active_record/transactions.rb:366:in `with_transaction_returning_status'
> activerecord-6.0.1/lib/active_record/transactions.rb:311:in `destroy'
> /var/www/discourse/app/models/upload.rb:112:in `block in destroy'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `block in transaction'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
> /usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction'
> activerecord-6.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `transaction'
> activerecord-6.0.1/lib/active_record/transactions.rb:212:in `transaction'
> /var/www/discourse/app/models/upload.rb:110:in `destroy'
> activerecord-6.0.1/lib/active_record/persistence.rb:551:in `destroy!'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:70:in `block (2 levels) in find_each'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:70:in `each'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:70:in `block in find_each'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:136:in `block in find_in_batches'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:238:in `block in in_batches'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:222:in `loop'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:222:in `in_batches'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:135:in `find_in_batches'
> activerecord-6.0.1/lib/active_record/relation/batches.rb:69:in `find_each'
> /var/www/discourse/app/jobs/scheduled/clean_up_uploads.rb:16:in `execute'
> /var/www/discourse/app/jobs/base.rb:232:in `block (2 levels) in perform'
> rails_multisite-2.0.7/lib/rails_multisite/connection_management.rb:63:in `with_connection'
> /var/www/discourse/app/jobs/base.rb:221:in `block in perform'
> /var/www/discourse/app/jobs/base.rb:217:in `each'
> /var/www/discourse/app/jobs/base.rb:217:in `perform'
> /var/www/discourse/app/jobs/base.rb:279:in `perform'
> mini_scheduler-0.12.2/lib/mini_scheduler/manager.rb:86:in `process_queue'
> mini_scheduler-0.12.2/lib/mini_scheduler/manager.rb:36:in `block (2 levels) in initialize'
> 
> ```

고맙습니다!

---

_[View the full topic](https://meta.discourse.org/t/tombstone-directory-not-getting-cleaned-up-for-images/106575)._
