6

I am trying to destroy an object within my ROR app.

But I get the following error:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "mailboxer_conversation_opt_outs" does not exist
LINE 5:                WHERE a.attrelid = '"mailboxer_conversation_o...
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"mailboxer_conversation_opt_outs"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:733:in `column_definitions'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:186:in `columns'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/schema_cache.rb:43:in `columns'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/schema_cache.rb:49:in `columns_hash'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:85:in `column_for'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:94:in `bind'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:103:in `last_chain_scope'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/associations/association_scope.rb:139:in `add_constraints'
... 72 levels...
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:281:in `block in destroy'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:220:in `transaction'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/transactions.rb:281:in `destroy'
    from (irb):5
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'

I'm guessing this is related to this mailboxer_conversation_opt_outs table I don't have within my app.

I'm using Rails 4.2 and:

mailboxer (0.13.0)
  carrierwave (>= 0.5.8)
  foreigner (>= 0.9.1)
  rails (>= 3.2.0)

Is there a migration file I somehow missed?

Anyway, how come my object is connected to this table while the actual object cannot send messages?

Thanks

Augustin Riedinger
  • 20,909
  • 29
  • 133
  • 206
  • 1
    Did you try running `rake db:migrate`? Do you have `20131206080416_add_conversation_optout` in your `schema_migrations` table? – dan-klasson Jan 31 '17 at 12:41
  • Nope. I'm guessing this migration has been added *after* I set up mailboxer at first (~3 years ago), right? How am I supposed to catch up on this? – Augustin Riedinger Jan 31 '17 at 13:07
  • Well I would look if that migration exists in your `schema_migrations` table. And on my local I would drop the db and re-create it and run the migrations again and see if that resolved it – dan-klasson Jan 31 '17 at 15:53
  • The migration doesn't exists and my issue is happening in production so I can't afford dropping my database... If this is from a newer version, I guess there should be some upgrade steps that I missed or something? – Augustin Riedinger Jan 31 '17 at 16:41

2 Answers2

4

Is there a migration file I somehow missed?

Yes, see itsnikolay's answer and the Upgrading section of the documentation.

Anyway, how come my object is connected to this table while the actual object cannot send messages?

Your Model class is probably still calling the acts_as_messageable method, which includes the Mailboxer::Models::Messageable Module into your ActiveRecord class, which declares several extra associations on your model. If you don't care about upgrading Mailboxer and just want to disconnect your model from Mailboxer entirely, just delete the acts_as_messageable line and you should be able to destroy your records without any more failed association issues.

Community
  • 1
  • 1
wjordan
  • 19,770
  • 3
  • 85
  • 98
2

It looks like you use previous version of Mailboxer.

Try to migrate on new one:

$ rails generate mailboxer:namespacing_compatibility
$ rails generate mailboxer:install -s
$ rake db:migrate

Taken from documentation: https://github.com/mailboxer/mailboxer#upgrading

itsnikolay
  • 17,415
  • 4
  • 65
  • 64