我试着玩不同的信息宝石,所有使用的设计。因此,在git的主分支上安装了Devise之后,我检查了一个新的分支来尝试一个创业板"rails消息传递“https://github.com/frodefi/rails-messaging,当我无法让它工作时,我提交了对该分支的更改,然后我返回到master并检查了一个新的分支来尝试另一个创业板"mailboxer”https://github.com/ging/mailboxer/tree/master/lib。在这个新分支的宝石文件中,没有第一个分支中的gems的踪迹,但是当我在安装gems之后尝试rake db:迁移到这个第二个分支时,我收到了以下错误消息,这似乎表明来自第一个分支的表正在干扰第二个分支的rake,除非执行以下操作。
rails g mailboxer:install它会自动运行rake :migrate。然而,README说我必须运行rake db:迁移,所以我不确定.
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "conversations" already exists: CREATE TABLE "conversations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "subject" varchar(255) DEFAULT '', "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
有人能建议我怎么解决这个问题吗?我真的不知道要运行哪些命令来解决这个问题。
这是scheme.rb文件。基于“消息传递用户”索引,我猜想这是rails消息传递创业板(在第一个分支上)创建的设置,但我不完全确定。我看了git上的源代码,但因为我经验不多,所以有点迷路了。
ActiveRecord::Schema.define(:version => 20120302041333) do
create_table "conversations", :force => true do |t|
t.string "subject", :default => ""
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "messaging_users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :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"
t.datetime "updated_at"
end
add_index "messaging_users", ["email"], :name => "index_messaging_users_on_email", :unique => true
add_index "messaging_users", ["reset_password_token"], :name => "index_messaging_users_on_reset_password_token", :unique => true
create_table "notifications", :force => true do |t|
t.string "type"
t.text "body"
t.string "subject", :default => ""
t.integer "sender_id"
t.string "sender_type"
t.integer "conversation_id"
t.boolean "draft", :default => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.integer "notified_object_id"
t.string "notified_object_type"
t.string "notification_code"
end
add_index "notifications", ["conversation_id"], :name => "index_notifications_on_conversation_id"
create_table "receipts", :force => true do |t|
t.integer "receiver_id"
t.string "receiver_type"
t.integer "notification_id", :null => false
t.boolean "read", :default => false
t.boolean "trashed", :default => false
t.boolean "deleted", :default => false
t.string "mailbox_type", :limit => 25
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "receipts", ["notification_id"], :name => "index_receipts_on_notification_id"
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :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"
t.datetime "updated_at"
t.string "name"
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发布于 2012-03-02 05:13:10
这里的问题是,虽然您的代码、模式、宝石和迁移存储在git中,但数据库本身却不是。因此,当您在分支之间切换时,数据库仍然保留其状态。
这些解决办法都将有效:
(在旧分支上)向下倾斜db:reset
rake db:schema:load
发布于 2012-06-14 15:35:39
是的,转换不同迁移级别的分支是一件很混乱的事情。没有“一条线”能正确地做到这一点。有四件事情可能不同步。你需要:
1)确定您的分支机构有哪些迁移:
(look at the contents of db/migrations)2)确定应用程序认为您的数据库是什么样子:
(look at db/schema.rb)3)通过查看schema_migrations表确定数据库认为有哪些迁移:
~> rails db console
(opens up your db console, in my case mysql...)
mysql> SELECT * FROM schema_migrations; # don't forget the ';' at the end!
(outputs big huge list of migration timestamps)4)查看实际的表,看看是否已经应用了迁移。
mysql> describe table_name;
(outputs the column names, see if they have been updated per the migration)5)现在需要思考的部分。有几种可能的情况。我只能和我遇到的那个人说话:
rake db:reset。它将破坏整个数据库,并从scratch重新创建结构。
https://stackoverflow.com/questions/9528242
复制相似问题