迁移显示为已关闭但已迁移?

ekr*_*aca 2 ruby-on-rails rails-migrations ruby-on-rails-3

我的rails应用程序有一些迁移.当我点击rake db:migrate:status以查看设置了什么状态时,所有状态********** NO FILE **********都已关闭.但是已经进行了迁移,因此模型方面似乎没有问题.这些文件可能有助于解释:

产量rake db:migrate:status:

 up     20130727003912  ********** NO FILE **********
down    20130728000151  Devise create users
down    20130728000335  Create friends
down    20130728000346  Create addresses
down    20130728000356  Create authies
down    20130728000413  Add indexes
Run Code Online (Sandbox Code Playgroud)

这时,rake db:migrate输出:

==  DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
NOTICE:  CREATE TABLE will create implicit sequence "users_id_seq1" for serial column "users.id"
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "users" already exists
: CREATE TABLE "users" ("id" serial primary key, "username" character varying(255), "email" character varying(255) DEFAULT '' NOT NULL, "encrypted_password" character varying(255) DEFAULT '' NOT NULL, "reset_password_token" character varying(255), "reset_password_sent_at" timestamp, "remember_created_at" timestamp, "sign_in_count" integer DEFAULT 0, "current_sign_in_at" timestamp, "last_sign_in_at" timestamp, "current_sign_in_ip" character varying(255), "last_sign_in_ip" character varying(255), "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) /home/ekrem/workspace/contactman/db/migrate/20130728000151_devise_create_users.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)

db/schema.rb:

ActiveRecord::Schema.define(:version => 20130727003912) do

  create_table "addresses", :force => true do |t|
    t.string   "title"
    t.text     "address"
    t.string   "phone"
    t.string   "city"
    t.integer  "friend_id"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.string   "slug"
    t.string   "country"
  end

  add_index "addresses", ["friend_id"], :name => "index_addresses_on_friend_id"
  add_index "addresses", ["slug"], :name => "index_addresses_on_slug", :unique => true

  create_table "authies", :force => true do |t|
    t.string   "provider"
    t.string   "uid"
    t.integer  "user_id"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end

  add_index "authies", ["user_id"], :name => "index_authies_on_user_id"

  create_table "friends", :force => true do |t|
    t.string   "name"
    t.string   "surname"
    t.integer  "user_id"
    t.datetime "created_at",            :null => false
    t.datetime "updated_at",            :null => false
    t.string   "slug"
    t.string   "imported_file_name"
    t.string   "imported_content_type"
    t.integer  "imported_file_size"
    t.datetime "imported_updated_at"
  end

  add_index "friends", ["slug"], :name => "index_friends_on_slug", :unique => true
  add_index "friends", ["user_id"], :name => "index_friends_on_user_id"

  create_table "users", :force => true do |t|
    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
    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.datetime "created_at",                             :null => false
    t.datetime "updated_at",                             :null => false
    t.string   "username"
  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

end
Run Code Online (Sandbox Code Playgroud)

如何解决此问题以使所有迁移看起来如何?

小智 6

您的用户表已在数据库中创建,但您的架构迁移未使用最新迁移进行更新.我不知道为什么它没有更新.您需要修复它,然后您可以通过两种方式执行此操作1.删除数据库并再创建一个或2.运行向下迁移然后向上迁移

rake db:drop
rake db:create
rake db:migrate
Run Code Online (Sandbox Code Playgroud)