Rails迁移不会更改schema.rb

编程入门 行业动态 更新时间:2024-10-11 17:18:54
本文介绍了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

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

发布评论

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

>www.elefans.com

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