ruby-on-rails – Rails 3.1使用change_table迁移添加列
发布时间:2020-12-17 03:13:07 所属栏目:百科 来源:网络整理
导读:我有一个名为profile的表,其中包含一些列. 现在,我希望使用rails 3.1中的change-method向该表添加几列.我使用以下代码创建了一个迁移: def change change_table :profiles do |t| t.string :photo t.string :name t.references :user endend 迁移工作完美,
我有一个名为profile的表,其中包含一些列.
现在,我希望使用rails 3.1中的change-method向该表添加几列.我使用以下代码创建了一个迁移: def change change_table :profiles do |t| t.string :photo t.string :name t.references :user end end 迁移工作完美,但是当我想要回滚时,我得到了 SQLite3::SQLException: duplicate column name: photo: ALTER TABLE "profiles" ADD "photo" varchar(255) 有什么想法吗? 解决方法
在Rails 3.1中添加列的自动生成的迁移格式如下:
class AddColumnToTable < ActiveRecord::Migration def change add_column :table,:column,:type end end 也许尝试那种语法? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |