ActiveRecord FOREIGN KEY constraint failed
% rails test test/controllers/posts_controller_test.rb Running 5 tests in a single process (parallelization threshold is 50) Run options: --seed 46393 # Running: ...E Error: PostsControllerTest#test_should_destroy_post: ActiveRecord::InvalidForeignKey: SQLite3::ConstraintException: FOREIGN KEY constraint failed app/controllers/posts_controller.rb:38:in `destroy' test/controllers/posts_controller_test.rb:33:in `block (2 levels) in <class:PostsControllerTest>' test/controllers/posts_controller_test.rb:32:in `block in <class:PostsControllerTest>'
Solution
# add all has_many :YOUR_MODEL, :dependent => :destroy class Post < ApplicationRecord belongs_to :user belongs_to :category has_many :comments, :dependent => :destroy end
https://stackoverflow.com/a/44075128/1399891