sqlite3 :: benteraintexception:外键约束失败:删除表用户



如何在 drop table 之前禁用(我还不知道正确的术语(外键?或

正确放下桌子的方法?

遵循此处提供的步骤

图像链接

再次获得相同的错误

(byebug) execute "PRAGMA foreign_keys = OFF"
-- execute("PRAGMA foreign_keys = OFF")
   -> 0.0009s
[]
(byebug) execute "DROP TABLE users"
-- execute("DROP TABLE users")
*** ActiveRecord::InvalidForeignKey Exception: SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE users
nil

假设您的用户与帖子表关联,然后创建迁移并删除

class RemoveForeignKey < ActiveRecord::Migration
  def change
    # remove the old foreign_key
    remove_foreign_key :posts, :users
  end
end

最新更新