测试版本Ruby:2.3.1   Rails:5.0.1

一、增加栏位

给devise默认的用户新增增加username字段

  1. $ rails generate migration add_username_to_users username:string

2. $ rake db:migrate

这样就成功的给users增加了一个username栏位

二、删除栏位

1. 增加一个栏位:

      rails g migration RemoveColumnFromTable column:type

增加多个栏位:

     rails g migration RemoveColumn1AndColumn2FromTable column1:type colummn2:type

2.rake db:migrate

Rails Migration Data Types – MySql – Postgresql – SQLite

Railsmysqlpostgresqlsqlite
:binaryblobbyteablob
:booleantinyint(1)booleanboolean
:datedatedatedate
:datetimedatetimetimestampdatetime
:decimaldecimaldecimaldecimal
:floatfloatfloatfloat
:integerint(11)integerinteger
:stringvarchar(255)*varchar(255)
:texttexttexttext
:timetimetimedatetime
:timestampdatetimetimestampdatetime
05-04 00:01