导轨:什么呢schema.rb办?

编程入门 行业动态 更新时间:2024-10-12 08:18:46
本文介绍了导轨:什么呢schema.rb办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我曾经以为 DB / schema.rb 中存储的数据库架构,使的Rails 项目的ActiveRecord 可以知道什么表/列它。

I used to think the db/schema.rb in a Rails project stored the database schema, so that ActiveRecord can know what table/column it has.

不过,早前我令人惊讶的发现我的项目运行正常后,我删除 DB / schema.rb !

But earlier I surprisingly noticed that my project runs normally after I delete db/schema.rb!

所以,因为的Rails 可以不用它的工作,是什么 schema.rb 真的?

So, since the Rails can work without it, what does schema.rb really do?

推荐答案

在 schema.rb 供应主要有两个目的:

The schema.rb serves mainly two purposes:

  • 它记录了数据库架构的最终当前状态。通常情况下,尤其是当你有不止一对夫妇迁移的,很难仅仅从单纯的迁移扣除架构。随着present schema.rb ,你可以去看看那里。 ActiveRecord的本身确实不使用它。运行时它会内省的数据库,因为这是更安全,而不是期望用户保持 schema.rb 最多最新的。然而,为了避免你的开发人员的困惑,你应该始终保持一个文件,该文件是最新的最新与您的迁移。

  • It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduct the schema just from the migrations alone. With a present schema.rb, you can just have a look there. ActiveRecord itself will indeed not use it. It will introspect the database during runtime as this is much safer than to expect users to keep the schema.rb up-to-date. However to avoid confusion of your developers, you should always maintain a file that is up-to-date with your migrations.

    据所使用的测试来填充数据库模式。作为这样的耙分贝:模式:转储常被作为耙的一部分运行测试:prepare 运行。其目的是测试数据库的模式发展现状数据库完全一致。

    It is used by the tests to populate the database schema. As such a rake db:schema:dump is often run as part of the rake test:prepare run. The purpose is that the schema of the test database exactly matches the current development database.

  • 更多推荐

    导轨:什么呢schema.rb办?

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

    发布评论

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

    >www.elefans.com

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