jeudi 6 août 2015

My database isn't running all of my migrations, but says the schema number has.

I was trying to fix a bad migration. I've reset my DB a couple times and its just causing further problems. Namely that not all my migrations are even running now.

I have below all the migrations, the one that was broken is the one yet to be run. But when I try to do a rake db:migrate I get this error:

undefined method to_sym' for nil:NilClass/usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_definitions.rb:258:in column'

This is an issue in itself but what is most confusing to me is that the migration to create the simulation table just isn't running. My scheme looks like this:

ActiveRecord::Schema.define(version: 20150806192507) do

  create_table "users", force: :cascade do |t|
    t.string   "email",              limit: 96, default: "", null: false
    t.string   "encrypted_password", limit: 60, default: "", null: false
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true

end

Any suggestions as too:

1. The simulations table is not being created. When I do a reset, and re-migrate.

2. The final migration to remove the verdict column is failing.

These are the migrations I have 1.

 class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Database authenticatable
      t.string :email,              :null => false, :default => "", limit: 96
      t.string :encrypted_password, :null => false, :default => "", limit: 60

      t.timestamps

      t.index :email, unique: true
    end
  end
end

2.

class CreateSimulations < ActiveRecord::Migration
  def change
    # Needs the hash column worked out before this is run 
    create_table :simulations do |t|
        t.integer :x_size
        t.integer :y_size
        t.string :verdict
        t.string :arrangement 
    end

    add_reference :simulations, :user, index: true    
  end
end

3.

    class AddOpinionToSimulation < ActiveRecord::Migration
      def change
        add_column :simulations, :opinion, :hash
      end
    end

Finally the bad one I was trying to run that started these problems (I have deleted the file to stop it from attempting to be migrated:

class RemoveVerdictFromSimulations < ActiveRecord::Migration
  def change
    remove_column :simulations, :verdict
  end
end

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire