我有一个Rails迁移,该迁移未应用于我的schema.rb。迁移应创建一个表:
I have a rails migration that is not being applied to my schema.rb. The migration should create a table:
class CreateUserGraphs < ActiveRecord::Migration def change create_table :user_graphs do |t| t.string :name t.string :content t.integer :user_id t.string :type_id t.integer :upload_id t.timestamps end add_index :user_graphs, [:user_id, :created_at] end end我做了db:reset。然后我尝试了rake db:migrate:up VERSION = 123123123(这是迁移号)。我在我的开发环境中。
I did db:reset. Then I tried rake db:migrate:up VERSION=123123123(this is the migration #). I am in my "dev" environment.
为什么迁移不影响schema.rb?
Why is the migration not affecting schema.rb?
推荐答案从文档:
rake db:reset 任务将删除数据库,重新创建数据库并将当前模式加载到其中。
The rake db:reset task will drop the database, recreate it and load the current schema into it.
与运行所有迁移不同。它将仅使用当前schema.rb文件的内容。如果迁移无法回滚,则 rake db:reset可能对您没有帮助。要了解有关转储模式的更多信息,请参见'schema dumping and you'。
This is not the same as running all the migrations. It will only use the contents of the current schema.rb file. If a migration can't be rolled back, 'rake db:reset' may not help you. To find out more about dumping the schema see 'schema dumping and you.'
所以 rake db:reset => db:drop db:create db:schema:load db:seed
要运行所有迁移,请使用: rake db:drop db:create db:migrate
To run all the migrations, use : rake db:drop db:create db:migrate
或 db:migrate:reset => rake db:drop db:create db:migrate
参考
更多推荐
Rails迁移不会更改schema.rb
发布评论