【发布时间】:2017-08-24 18:14:47
【问题描述】:
当我尝试在 ROR 中对我非常简单的应用程序运行测试时遇到错误。我正在网上学习一门课程,我有一个非常简单的数据库,它有两个表:posts(带有title 和body)和comments(带有ForeignKey:post_id 和body。当我运行时rake test我收到以下错误:
Error: PostsControllerTest#test_should_destroy_post:
ActiveRecord::InvalidForeignKey: SQLite3::ConstraintException: FOREIGN
KEY constraint failed: DELETE FROM "posts" WHERE "posts"."id" = ?
app/controllers/posts_controller.rb:57:in `destroy'
test/controllers/posts_controller_test.rb:43:in `block (2 levels) in <class:PostsControllerTest>'
test/controllers/posts_controller_test.rb:42:in `block in <class:PostsControllerTest>'
bin/rails test test/controllers/posts_controller_test.rb:41
....
Finished in 12.539965s, 1.1164 runs/s, 1.2759 assertions/s. 14 runs,
16 assertions, 0 failures, 1 errors, 0 skips`
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2