测试版本Ruby:2.3.1 Rails:5.0.1
一、增加栏位
给devise默认的用户新增增加username字段
- $ 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
Rails | mysql | postgresql | sqlite |
:binary | blob | bytea | blob |
:boolean | tinyint(1) | boolean | boolean |
:date | date | date | date |
:datetime | datetime | timestamp | datetime |
:decimal | decimal | decimal | decimal |
:float | float | float | float |
:integer | int(11) | integer | integer |
:string | varchar(255) | * | varchar(255) |
:text | text | text | text |
:time | time | time | datetime |
:timestamp | datetime | timestamp | datetime |