ruby-on-rails - 迁移显示为关闭但已迁移?

标签 ruby-on-rails ruby-on-rails-3 rails-migrations

我的 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

此时,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)

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

如何解决此问题以使所有迁移都正常运行?

最佳答案

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

rake db:drop
rake db:create
rake db:migrate

关于ruby-on-rails - 迁移显示为关闭但已迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18878490/

相关文章:

html - 给 SLIM 文件起什么名字? 。瘦? .html. slim ?

css - link_to 中的 rails 打印样式颜色

ruby-on-rails - Jammit::MissingConfiguration - precache_all':需要 --base-url 选项才能生成 MHTML

javascript - Angularjs ngResource '@id'

ruby-on-rails - 在 Ubuntu 12.04 LTS 上设置 Discourse

ruby-on-rails - Ruby on Rails : I want to remove non letters to create a username

ruby-on-rails - 如何将此 form_tag 助手转换为 simple_form_for 调用?

ruby-on-rails - 如何为所有 capybara 功能设置 http header

ruby-on-rails - 无法使用 Capistrano 重置/取消设置 VERSION 环境变量

ruby-on-rails - 将数据从已删除的列移动到刚刚在 Rails 迁移中创建的列