version: rails4
数据迁移
Rails 提供了一种基于领域的语言用来管理数据库模型,这称为数据转移。数据转移被保存为文件,能够在任何数据库中执行,Active Record 提供了命令 rake。下文是一个创建数据表的数据转移的例子:
classCreatePublications < ActiveRecord::Migration defchange create_table :publicationsdo|t| t.string :title t.text :description t.references :publication_type t.integer :publisher_id t.string :publisher_type t.boolean :single_issue
t.timestamps end add_index :publications, :publication_type_id end end |
Rails 保持了可追踪性对于那些已经被提交至数据库的文件,以及提供了回滚的特性。为了实际地创建数据表,你要运行 rake db:migrate,为了回滚,需要运行 rake db:rollback.
注意,上文的代码是无关乎数据库的:它可以运行在 MySQL,PostgreSQL,Oracle 和其他的数据库。
original: http://guides.rubyonrails.org/active_record_basics.html#migrations
相关推荐
ffmpeg basics ffmpeg basics ffmpeg basics ffmpeg basics ffmpeg basics
And almost all of those books actually do a great job of introducing you to the basics of Active Record; they go a long way toward getting you started with the library. However, because they ...
信息安全_数据安全_Going Beyond the Basics An Advan 数据智能 安全防护 情报处理 数据安全 自动化
MPLS BasicsMPLS Basics
FFmpeg Basics
Python Basics with Numpy Python Basics with Numpy Python Basics with Numpy
Stepper Motor Basics
信息安全_数据安全_A Crash Course in Cyber Threat Intelligence Basics 数字认证 数据分析 安全建设 安全审计 安全威胁
FFmpeg Basics = 119.pdf
LabWindows CVI BASICS I & II 英文版的都是
The Basics of Cloud Computing
Welcome to HTML Basics. This workshop leads you through the basics of Hyper Text Markup Language (HTML). HTML is the building block for web pages. You will learn to use HTML to author an HTML page to ...
Basics of Holography.pdf
Blockchain Basics A Non-Technical Introduction in 25 Steps 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Basics of CMOS Cell Design
clojure-basics-源码.rar
LabVIEWTM Basics I: Introduction Course Manual (498页)
Gradle Beyond the Basics
RF Basics_AN5300 describe some rf basic concept
英语原版 MSP430 Microcontroller Basics.pdf