title: "PG::UndefinedTable: ERROR: relation does not exist" with a correct Rails naming and convention
body: <p>I've read a lot of potsts like this, but all the solutions I've seen are in the nomenclature of the models, naming and Rails convention.</p>
  
  <p>Now I have this problem when <strong>I run for first time in production environment in  PostgreSQL 9.1</strong></p>
  
  <pre><code>    rake db:migrate RAILS_ENV=production
  </code></pre>
  
  <p>or</p>
  
  <pre><code>    rake db:schema:load RAILS_ENV=production 
  </code></pre>
  
  <p>I could create database without problems: <code>rake db:create RAILS_ENV=production</code> =>OK</p>
  
  <p>The error is</p>
  
  <pre><code>rake aborted!
  PG::UndefinedTable: ERROR:  relation "categories" does not exist
  LINE 5:                WHERE a.attrelid = '"categories"'::regclass
                                            ^
  :               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 = '"categories"'::regclass
                   AND a.attnum &gt; 0 AND NOT a.attisdropped
                 ORDER BY a.attnum
  </code></pre>
  
  <p>And the models follows all Rails naming convention. So that, I don't know what this error is telling me 
  <strong>¿There is something else that can cause this error?</strong></p>
  
  <p>The models:</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    has_many :subcategories
  end
  
  class Subcategory &lt; ActiveRecord::Base
    belongs_to :category
  end
  </code></pre>
  
  <p>shema.rb:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: nnnn) do
  
    # These are extensions that must be enabled in order to support this database
    enable_extension "plpgsql"
  
    create_table "categories", force: true do |t|
      t.string   "name"
      t.text     "comments"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.decimal  "amount_need_comments",           precision: 6, scale: 2
      t.decimal  "amount",                         precision: 6, scale: 2
      t.decimal  "amount_per_unit",                precision: 6, scale: 2
      t.integer  "teletrabajo",          limit: 2,                         default: 0, null: false
      t.decimal  "amount_need_city",               precision: 6, scale: 2
    end
  
    create_table "subcategories", force: true do |t|
      t.string   "name"
      t.text     "comments"
      t.integer  "category_id"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.decimal  "amount_need_comments", precision: 6, scale: 2
      t.decimal  "amount",               precision: 6, scale: 2
      t.decimal  "amount_per_unit",      precision: 6, scale: 2
      t.decimal  "amount_need_city",     precision: 6, scale: 2
    end
  </code></pre>
  
  <p>And finally, I tried something like this, without success</p>
  
  <p>inflections.rb</p>
  
  <pre><code>ActiveSupport::Inflector.inflections do |inflect|
    inflect.irregular 'category', 'categories'
    inflect.irregular 'subcategory', 'subcategories'
  
    inflect.plural 'category', 'categories'
    inflect.plural 'subcategory', 'subcategories'
  end
  </code></pre>
  
  <p>And remove the relationship of the models involved, like this:</p>
  
  <pre><code>class ExpenseDetail &lt; ActiveRecord::Base
    # belongs_to :expense
    # belongs_to :category
    # belongs_to :subcategory
  
    default_scope :order=&gt;"id"
  
    validate :expense_date...
  </code></pre>
  
  <p>...</p>