create the model and table

原创 2007年09月14日 10:26:00

 work>ruby script/generate model product

the generator creates a bunch of files. The two we're interested in are the model itself product.rb, and the migration 001_create_products.rb.

In this file, there were two ruby methods.

class CretaeProducts < ActiveRecord::Migration

def self.up

  create_table :products do |t|

    t.column :title,  :string

    t.column :description, :text

  end

def self.down

  drop_table :products

end

end

get rails to apply the migration to the database.

work> rake db:migrate

if you want to roll back ,you could use

work> rake db:migrate VERSION=0

and the products table will gone.

call the rake db:migrate will re-create it.

相关文章推荐

android in practice_create model、table class and sqlitehelper(MyMoviesDataBases project)

In essence, cursors iterate over result sets and provide access to data one row at a time. firs...

171.View the Exhibit and examine the command used to create the ZONEDATA table.

171.View the Exhibit and examine the command used to create the ZONEDATA table.

abap create dynamic structure and dynamic table

 本文介绍几个创建动态内表和结构的方法 曾经在网上大量搜索创建dynamic structure的方法。方法是有,大家都是先创建dynamic table, 再通过动态内表,创建dyna...

Create country table and insert all the countries script for SQL Server

INSERT INTO [country]([countryName],[countryCode])VALUES('AFGHANISTAN','AF'); INSERT INTO [country]...

create table

  • 2012年12月01日 19:57
  • 6KB
  • 下载

CoreData报错:The model used to open the store is incompatible with the one used to create the store

今天在调试coredata,出现了这个异常: 在推酷看到解决方法:这个错误通常是我们修改了DataModel文件,增加了新的Entity,包括Attribute属性、Relationship关系等等...
  • QZidane
  • QZidane
  • 2015年05月09日 11:06
  • 956

Halcon算子_create_aniso_shape_model

create_aniso_shape_model(Template : : NumLevels, AngleStart, AngleExtent, AngleStep, ScaleRMin, Sca...

Android 判断SQLite数据库中是否存在某一个表格: CREATE TABLE IF NOT EXISTS

初始化SQL脚本 安装软件时要初始化数据库,通常的需求是新建表、索引、视图、存储过程等对象,插入初始数据。Oracle没有drop table if exists或create table ...
  • haiross
  • haiross
  • 2014年11月13日 16:19
  • 28688
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:create the model and table
举报原因:
原因补充:

(最多只允许输入30个字)