title: Weird Rails migration / schema.rb issue
body: <p>A while back I ran the following migration:</p>
  
  <pre><code>class CreatePipelineSpecs &lt; ActiveRecord::Migration
    def change
      create_table :pipeline_specs do |t|
        t.integer :id_no
        t.string :od
        t.string :wt
        t.string :material
        t.string :spec_type
        t.string :spec_grade
        t.string :mop
        t.string :stress_level
        t.string :joints
        t.text :notes
        t.string :ip
        t.references :pipeline, index: true, foreign_key: false
  
        t.timestamps null: false
      end
      add_index :pipeline_specs, :id_no
    end
  end
  </code></pre>
  
  <p>I am not sure what has happened now but every time I run <code>rake db:migrate</code> the <code>scheme.rb</code> file gets updated with:</p>
  
  <pre><code>  create_table "pipeline_specs", force: :cascade do |t|
      t.integer  "id_no"
      t.string   "od"
      t.string   "wt"
      t.string   "material"
      t.string   "spec_type"
      t.string   "spec_grade"
      t.string   "mop"
      t.string   "stress_level"
      t.string   "joints"
      t.text     "notes"
      t.string   "ip"
      t.integer  "pipelines_id"
      t.datetime "created_at",   null: false
      t.datetime "updated_at",   null: false
    end
  
    add_index "pipeline_specs", ["id_no"], name: "index_pipeline_specs_on_id_no", using: :btree
    add_index "pipeline_specs", ["pipelines_id"], name: "index_pipeline_specs_on_pipelines_id", using: :btree
  </code></pre>
  
  <p>Note the plural <strong>pipelines_id</strong>.  The actual database tables (dev, production etc.) are all <strong>pipeline_id</strong> which is correct as the reference table is <code>Pipeline</code>.  So I add a new unrelated migration and the <code>schema.rb</code> gets updated and these get changed back to plural again after I change them back.  If I forget to change them when I run tests everything breaks as the wrong schema gets loaded into the test environment.</p>
  
  <p>I am at a loss here.  I am I missing something obvious here or is there some hidden migration schema table etc.</p>
  
  <p>The only think I can this of is when I made the original migration I used <code>pipelines:references</code> vs <code>pipeline:references</code>, then fixed my mistake, and then cleaned up the migrations before committing this and deploying it.</p>
  
  <p>Any ideas here one why this is happening and how to fix it once and for all?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here are my three related models:</p>
  
  <pre><code>irb(main):031:0&gt; Pipeline
  =&gt; Pipeline(id: integer, licence: string, company: string, company_id: integer, ba_code: string, substance_code: string, substance: string, h2s: string, partial_pressure: string, notes: text, created_at: datetime, updated_at: datetime, slug: string)
  irb(main):032:0&gt; PipelineSpec
  =&gt; PipelineSpec(id: integer, id_no: integer, od: string, wt: string, material: string, spec_type: string, spec_grade: string, mop: string, stress_level: string, joints: string, notes: text, ip: string, pipeline_id: integer, created_at: datetime, updated_at: datetime, slug: string)
  irb(main):033:0&gt; PipelineSegment
  =&gt; PipelineSegment(id: integer, line: integer, lsd_from: integer, sec_from: integer, twp_from: integer, rge_from: integer, m_from: integer, fc_from: string, lsd_to: integer, sec_to: integer, twp_to: integer, rge_to: integer, m_to: integer, fc_to: string, length: string, aasm_state: string, state_comment: string, state_user_id: integer, aasm_date: datetime, env: string, volume: string, notes: text, pipeline_id: integer, pipeline_spec_id: integer, created_at: datetime, updated_at: datetime, slug: string)
  </code></pre>
  
  <p><code>Pipeline</code> has_many <code>PipelineSpec</code> and <code>PipelineSegment</code>.  <code>PipelineSegment</code> has_one <code>PipelineSpec</code>.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Checked my test environment schema - it's fine.  Ran rake db:migrate and again the <code>schema.rb</code> gets updated.  Run the tests again and get gobs of:</p>
  
  <pre><code>ActiveRecord::StatementInvalid:         ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "pipeline_id" of relation "pipeline_specs" does not exist
          LINE 1: ..., "mop", "stress_level", "joints", "notes", "ip", "pipeline_...
                                                                       ^
          : INSERT INTO "pipeline_specs" ("id", "id_no", "od", "wt", "material", "spec_type", "spec_grade", "mop", "stress_level", "joints", "notes", "ip", "pipeline_id", "created_at", "updated_at") VALUES (1, 1, '88.9', '3.18', 'S', 'Z245.1', '359 2', '9930', '25', 'W', 'MyText', 'U', 1, '2017-04-24 03:47:26', '2017-04-24 03:47:26')
  </code></pre>
  
  <p>as the fixtures try to load into the incorrect test schema that was just loaded at test time.</p>