0
我正在潜入RoR,我需要删除模型及其表格,并更新引用它的其他模型。我在Google上搜索过,所以我发现的最佳答案是this,但答案并不明确。最终的共识是使用ruby script/destroy model
方法,然后使用“手动编辑任何可能包含这些已删除模型参考的迁移”这是我不清楚的最后一部分。我想删除的模型我user
和profile
模式和表...如何在Ruby on Rails中删除模型及其表格?
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :email
t.string :password
t.timestamps
end
end
def self.down
drop_table :users
end
end
class CreateProfiles < ActiveRecord::Migration
def self.up
create_table :profiles do |t|
t.string :name
t.integer :user_id
t.timestamps
end
end
def self.down
drop_table :profiles
end
end
和更新article
模型和表引用他们...
class CreateArticles < ActiveRecord::Migration
def self.up
create_table :articles do |t|
t.string :title
t.text :body
t.datetime :published_at
t.string :image
t.timestamps
end
end
def self.down
drop_table :articles
end
end
class AddUserIdToArticles < ActiveRecord::Migration
def self.up
add_column :articles, :user_id, :integer
end
def self.down
remove_column :articles, :user_id
end
end
可我只是做ruby script/destroy user
和然后在article
迁移中调用self.down
方法?如果是这样,我该如何称呼'self.down`方法和顺序?
非常感谢您的帮助!