Rails: How to create database schema with ActiveRecord::Schema like in django?
I like Rails, but I'm not a big fan of migrations.
How can I use the ActiveRecord::Scema tool to create a database without using SQL and without migrations?
I know you use it like this:
ActiveRecord::Schema.define do
create_table :authors do |t|
t.string :name, :null => false
end
add_index :authors, :name, :unique
create_table :posts do |t|
t.integer :author_id, :null => false
t.string :subject
t.text :body
t.boolean :private, :def开发者_开发问答ault => false
end
add_index :posts, :author_id
end
But how do you run this?
Please don't recommend to use migrations, because I... simply don't like them.
Well migrations are the best way to manage the evolutions of your database ;)
However you can directly load a schema.rb into your database if you wish to.
rake db:schema:load
I wouldn't recomment it however.
try rake db:schema:load
精彩评论