【问题标题】:how i can remove tables my.sql by ruby on rails我如何通过 ruby​​ on rails 删除表 my.sql
【发布时间】:2020-09-20 10:30:56
【问题描述】:

我如何回滚或删除此公式干净我尝试 def up 和 def down 但不迁移

 class AllowAllTrackersAsSubtasks < ActiveRecord::Migration[5.1]
  def change
    trackers = Tracker.all
    trackers_ids = trackers.pluck(:id)
    trackers.each do |tracker|
      tracker.subtask_ids = trackers_ids
      tracker.save
    end
  end
end

这是另一个代码

class CreateTrackerSubtask < ActiveRecord::Migration[5.1]
  def change
    create_table "trackers_subtasks", :id => false, :force => true do |t|
      t.column "tracker_id", :integer, :default => 0, :null => false
      t.column "subtask_id", :integer, :default => 0, :null => false
      t.index [:tracker_id, :subtask_id], :unique => true
    end
  end
end

【问题讨论】:

  • 您是否创建了迁移以删除该表?有什么理由不能选择吗?
  • 是的,但我想删除我所做的,我如何删除表格,
  • 类 CreateTrackerSubtask false, :force => true do |t| t.column "tracker_id", :integer, :default => 0, :null => false t.column "subtask_id", :integer, :default => 0, :null => false t.index [:tracker_id, : subtask_id], :unique => true end end

标签: mysql ruby-on-rails ruby


【解决方案1】:

这段代码有效吗??

class CreateTrackerSubtask < ActiveRecord::Migration[5.1]
  def change
    drop_table "trackers_subtasks", :id => false, :force => true do |t|
      t.column "tracker_id", :integer, :default => 0, :null => false
      t.column "subtask_id", :integer, :default => 0, :null => false
      t.index [:tracker_id, :subtask_id], :unique => true
    end
  end

还有什么代码我该怎么办?

【讨论】:

  • 你运行它时发生了什么,它有效吗?有点不清楚您是在问这是否可行或是否可行。
  • 是的,我想在我的数据库中删除我所做的所有事情,但没有效果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
相关资源
最近更新 更多