那么在Rails 2中在Sqlite数据库中创建新表的最佳方法是什么。我使用rake db:migrate命令创建了数据库。 所以我应该编写单独的sql脚本来创建数据库或以某种方式使用rake。 我不需要脚手架。
So what's the best way to create new tables in a Sqlite database in Rails 2. I have created the database using rake db:migrate command. So should I write individual sql scripts to create a database or use rake somehow. I don't need scaffolding.
最满意答案
基本上使用迁移。
有关如何使用迁移的一些有用帮助,请访问http://wiki.rubyonrails.org/rails/pages/understandingmigrations和http://wiki.rubyonrails.org/rails/pages/UsingMigrations 。 我使用的好的备忘单也可以在http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations上找到 。
基本上,迁移使用ruby代码为您创建数据库表。 更容易(至少在我看来)使用漂亮的ruby代码而不是SQL DDL - 它也会自动为你做各种事情(比如像rails需要的那样在你的所有表中添加id字段)。 然后,您可以使用rake任务将迁移实际应用于数据库。 迁移为您提供的另一个主要优点是它们是可反向的 - 因此您的数据库是版本化的,您可以轻松地从一个版本跳转到另一个版本。
Basically use migrations.
Some useful help on how to use migrations is available at http://wiki.rubyonrails.org/rails/pages/understandingmigrations and http://wiki.rubyonrails.org/rails/pages/UsingMigrations. A good cheatsheet that I use is also available at http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations.
Basically migrations use ruby code to create your database tables for you. It is far easier (in my opinion at least) to use nice ruby code to do this rather than SQL DDL - it also does various things automatically for you (like adding id fields to all your tables as rails requires). You can then use rake tasks to actually apply the migrations to your database. The other major advantage that migrations give you is that they are reverseable - so your database is versioned and you can easily jump from one version to another.
更多推荐
发布评论