Rails耙db:structure:load与耙db:schema:load [英] Rails rake db:structure:load vs. rake db:schema:load

查看:115
本文介绍了Rails耙db:structure:load与耙db:schema:load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结构是数据库的 sql 版本,而架构是数据库的 Rails 版本吗?您什么时候要加载?还是有所作为?

Is the structure just a sql version of the db while the schema is a Rails version of the db? When would you want to load either? Or does it make a difference?

推荐答案

模式文件是数据库的Rails版本,并且不包含任何特定的数据库诸如视图,触发器之类的东西。

The schema file is the Rails version of your db and doesn't contain any db specific stuff like, views, triggers, and so on.


db / schema.rb无法表示特定于数据库的项,例如触发器,
序列,存储过程或检查约束等。请注意
,尽管可以在迁移中运行自定义SQL语句,但是架构转储程序无法重构这些
语句。如果您是
的用户,则应将架构格式设置为
:sql。
http://edgeguides.rubyonrails.org/active_record_migrations。 html#schema-dumping-and-you

何时使用另一个取决于您是否拥有数据库您需要的特定内容。如果您只使用基本表,带有索引以及主键和外键,那么您最好使用模式文件。

When would you use one over the other depends on whether you have db specific stuff that you need. If all you use are the basic tables, with indexes and primary and foreign keys you are good to go with schema files.

在我看来,我始终使用 structure.sql ,因为我总是使用一些特定于数据库的东西。

In my opinion however I always use structure.sql since I always use some db specific things.

您可以通过更改以下格式来更改要使用的格式您的 config / application.rb 文件。

You can change what format you want to use by changing this in your config/application.rb file.

config.active_record.schema_format = :sql # default is :ruby 

这篇关于Rails耙db:structure:load与耙db:schema:load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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