ruby-on-rails – Rails Migration Change vs Up&Down方法
发布时间:2020-12-17 04:23:40 所属栏目:百科 来源:网络整理
导读:我正在阅读Rails测试处方书,在设置过程中,它要求我将迁移文件更改为以下内容: class ProjectUserJoin ActiveRecord::Migration def self.up create_table :projects_users,:force = true,:id = false do |t| t.references :project t.references :user t.ti
我正在阅读Rails测试处方书,在设置过程中,它要求我将迁移文件更改为以下内容:
class ProjectUserJoin < ActiveRecord::Migration def self.up create_table :projects_users,:force => true,:id => false do |t| t.references :project t.references :user t.timestamps end end def self.down drop_table :projects_users end end 看起来我在Rails(4.0.0)上使用的是比书(2或3.x)更高的版本,我的迁移文件如下所示: class ProjectUserJoin < ActiveRecord::Migration def change end end 如何编辑更改方法以执行与上述上下方法相同的操作?到目前为止,我尝试使用up和down而不是self.up和self.down并使用相同的代码进行复制.那没起效. 谢谢! 解决方法
只需使用def self.up内容更改def更改.
您可以通过在控制台上运行rake db:migrate来检查结果 – 它将创建表(self.up功能)和rake db:rollback – 它将删除表(self.down功能). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |