我有一些迁移和现有的schema.rb
。
我确实拥有了包含记录的所需表格,在开发过程中的某个时刻,我意识到我无法重新创建迁移。
现在我遇到了奇怪的情况:
当我删除数据库并重新运行迁移时,不会抛出任何异常,但未列出迁移且未创建表:
$ bin/rake db:drop
$ bin/rake db:create
$ bin/rake db:migrate
但是,当我运行迁移时,之前包含所有已创建表的schema.rb
现在看起来像这样:
ActiveRecord::Schema.define(version: 0) do
end
此gist包含原始schema.rb
以及迁移。
这是我的database.yml
:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: dev_db
pool: 5
username: root
password:
host: localhost
更新:
我可以通过运行bin/rake db:schema:load
重新创建我的数据库。但是,只要我再次运行迁移,整个过程就会被恢复,所有迁移都会降级,我最终会再次出现空schema.rb
:
$ bin/rails g migration AddBubuToUser bubu:string
invoke active_record
create db/migrate/20151203104243_add_bubu_to_user.rb
$ bin/rake db:migrate
== 20151203092755 RemoveNameFromUser: reverting ===============================
-- add_column(:users, :name, :string)
-> 0.0179s
== 20151203092755 RemoveNameFromUser: reverted (0.0215s) ======================
== 20151203092753 AddNameToUser: reverting ====================================
-- remove_column(:users, :last_name, :string)
-> 0.0188s
-- remove_column(:users, :first_name, :string)
-> 0.0176s
== 20151203092753 AddNameToUser: reverted (0.0369s) ===========================
== 20151203091637 AddRoleToUsers: reverting ===================================
-- remove_column(:users, :role, :integer)
-> 0.0253s
== 20151203091637 AddRoleToUsers: reverted (0.0256s) ==========================
== 20151203091630 AddNameToUsers: reverting ===================================
-- remove_column(:users, :name, :string)
-> 0.0125s
== 20151203091630 AddNameToUsers: reverted (0.0128s) ==========================
== 20151203091627 DeviseCreateUsers: reverting ================================
-- remove_index(:users, {:column=>:reset_password_token})
-> 0.0214s
-- remove_index(:users, {:column=>:email})
-> 0.0200s
-- drop_table(:users)
-> 0.0010s
== 20151203091627 DeviseCreateUsers: reverted (0.0432s) =======================