Rails 迁移不会改变 schema.rb [英] Rails migration does not change schema.rb
问题描述
我有一个未应用于我的 schema.rb 的 rails 迁移.迁移应该创建一个表:
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' 可能帮不了你.要了解有关转储架构的更多信息,请参阅'模式倾销和你.'
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!