简体   繁体   English

可以在rails上的ruby中使用“数据库优先”方法吗?

[英]Possible to use a “database first” approach in ruby on rails?

是否可以在GUI mysql管理器中创建db模式,然后基于此模式创建(或更新)模型?

This is what migrations are for. 这就是迁移的目的。 Once you learn the DSL, writing migrations (esp. with the built-in generators) is much easier than fiddling with a GUI to create tables. 一旦你学习了DSL,编写迁移(特别是使用内置生成器)比摆弄GUI来创建表要容易得多。 Check out the migrations guide for detailed info. 查看迁移指南以获取详细信息。

ActiveRecord already does a lot automatically based on the database schema, such as adding getters and setters based on columns. ActiveRecord已经基于数据库模式自动执行了很多操作,例如根据列添加getter和setter。 I'm not sure what more you're wanting, so I dont know how to help you any more specifically. 我不确定你还想要什么,所以我不知道如何更专门地帮助你。

Migrations might look confusing on first sight, but once you get used to them migrations work naturally in Rails. 迁移可能看起来很混乱,但是一旦习惯了它们,迁移在Rails中自然会起作用。 If you mistype a name, you just rollback and correct the migration file. 如果您输入错误的名称,则只需回滚并更正迁移文件即可。 Or write another mig that corrects the error in the rare case you used it on the production db. 或者编写另一个mig来纠正错误,在极少数情况下,您在生产数据库中使用它。

They give you far more power, especially if your project went through several version stages. 它们为您提供了更多功能,特别是如果您的项目经历了多个版本阶段。 You can at any point rollback and migrate to any former state and when you add new columns you can easily set default values or write short ruby scripts that adjusts values or relations. 您可以随时回滚并迁移到任何以前的状态,当您添加新列时,您可以轻松设置默认值或编写调整值或关系的简短ruby脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM