Testing with rspec is causing an error: `Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development `

Testing with rspec is causing an error: `Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development `

when I run the rails server, localhost displays this error:
ActiveRecord::PendingMigrationError (Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development):

I have run the bin/rake... and the next error says:

 $ bundle exec bin/rake db:migrate RAILS_ENV=development  
  == 20150225172130 CreateVotes:
 migrating ======================================
-- create_table(:votes)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

  SQLite3::SQLException: table "votes" already exists: CREATE TABLE "votes" 
  ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "value" varchar(255), 
 "user_id" integer, "post_id" integer, "created_at" datetime, "updated_at"  
 datetime) 

_create_votes.rb

class CreateVotes < ActiveRecord::Migration
  def change
create_table :votes do |t|
  t.string :value
  t.references :user, index: true
  t.references :post, index: true

  t.timestamps
    end
  end
end

Basically, it tells me I have migrations pending, but when I attempt to migrate it says the table already exists.

20150225172130 CreateVotes: 
migrating ======================================
-- create_table(:votes)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "votes" already exists: CREATE TABLE "votes"...

after running db:drop:all db:create db:migrate db:test:clone

votes are now showing up in schema.rb:

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

  create_table "comments", force: true do |t|
t.text     "body"
t.integer  "post_id"
t.datetime "created_at"
t.datetime "updated_at"
  end

  add_index "comments", ["post_id"], name: "index_comments_on_post_id"

  create_table "posts", force: true do |t|
    t.string   "title"
    t.text     "body"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "users", force: true do |t|
    t.string   "name"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.string   "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string   "unconfirmed_email"
    t.datetime "created_at"
    t.datetime "updated_at"
      end

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

  create_table "votes", force: true do |t|
t.integer  "value"
t.integer  "user_id"
t.integer  "post_id"
t.datetime "created_at"
t.datetime "updated_at"
  end

  add_index "votes", ["post_id"], name: "index_votes_on_post_id"
  add_index "votes", ["user_id"], name: "index_votes_on_user_id"
        end

model/vote.rb

class Vote < ActiveRecord::Base
  belongs_to :user
  belongs_to :post

end

你可以这样做:

class CreateVotes < ActiveRecord::Migration


def change
  unless table_exists? :votes
    create_table :votes do |t|
      t.string :value
      t.references :user, index: true
      t.references :post, index: true

      t.timestamps
    end
  end
end

我之前 运行 参与过这个,当时迁移没有按预期 运行 进行。但是您还应该检查 schema.rb 文件以确保投票 table 具有迁移添加的列。