Rails 迁移不会改变 schema.rb

编程入门 行业动态 更新时间:2024-10-11 19:23:51
本文介绍了Rails 迁移不会改变 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

本文发布于:2023-10-18 04:24:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503092.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   schema   rb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!