Rails迁移不会更改schema.rb [英] Rails migration does not change schema.rb

查看:90
本文介绍了Rails迁移不会更改schema.rb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆