SQLite3::ConstraintException:FOREIGN KEY 约束失败:DROP TABLE 用户
SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE users
如何在 DROP TABLE 之前禁用(我还不知道正确的术语)外键?
或者
删除 table 的正确方法?
遵循提供的步骤here
Image link
再次遇到同样的错误SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE users.
(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
假设您的用户与帖子相关联 table 然后创建迁移并删除
class RemoveForeignKey < ActiveRecord::Migration
def change
# remove the old foreign_key
remove_foreign_key :posts, :users
end
end
如何在 DROP TABLE 之前禁用(我还不知道正确的术语)外键? 或者
删除 table 的正确方法?
遵循提供的步骤here
Image link
再次遇到同样的错误SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE users.
(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
假设您的用户与帖子相关联 table 然后创建迁移并删除
class RemoveForeignKey < ActiveRecord::Migration
def change
# remove the old foreign_key
remove_foreign_key :posts, :users
end
end