Skip to content

Instantly share code, notes, and snippets.

@rickywid
Created August 10, 2015 19:20
Show Gist options
  • Save rickywid/85c64f6e2b1f65af6c74 to your computer and use it in GitHub Desktop.
Save rickywid/85c64f6e2b1f65af6c74 to your computer and use it in GitHub Desktop.
rails generate model Micropost content:text user:references
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.text :content
t.references :user, index: true, foreign_key: true
t.timestamps null: false
end
end
end
==============================================================
rails generate model Micropost content:text user:references
class CreateMicroposts < ActiveRecord::Migration
def change
create_table :microposts do |t|
t.text :content
t.references :user, index: true
t.timestamps null: false
end
add_foreign_key :microposts, :users
add_index :microposts, [:user, :created_at]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment