M
M
Max Yawo2015-07-13 23:00:44
PostgreSQL
Max Yawo, 2015-07-13 23:00:44

postgresql + apartment. Migrations issue, column "database" does not exist?

Added username column to User (devise)

class AddUsernameToUser < ActiveRecord::Migration
  def change
      add_column :users, :username, :string, null: false

      add_index :users, :username, unique: true
  end
end

and configured the apartment gem so that username would be a subdomain, i.e. username.local.dev for example.
This works, despite the fact that the migration does not complete, it crashes with an error:
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "database" does not exist
LINE 1: SELECT database FROM "public"."users"
               ^
: SELECT database FROM "public"."users"
/Users/mihail/Documents/workspace/work/RailsApp/s4t/config/initializers/apartment.rb:26:in `block (2 levels) in <top (required)>'
PG::UndefinedColumn: ERROR:  column "database" does not exist
LINE 1: SELECT database FROM "public"."users"
               ^
/Users/mihail/Documents/workspace/work/RailsApp/s4t/config/initializers/apartment.rb:26:in `block (2 levels) in <top (required)>'
Tasks: TOP => apartment:migrate
(See full trace by running task with --trace)

What could be the problem, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-07-14
@Zlat1997

You have not fully configured apartment. In the config/initializers/apartment.rb file, on line 26, you need to specify an array of all available tenants, that is, subdomains in your case. Since you are storing them in the username column of the User model, this line should look like this:

config.tenant_names = lambda { User.pluck :username }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question