Error when I run rake test in Ruby on Rails

KH_

I am getting an error when I try to run a test on my very simple app in ROR. I am taking a course online and I have this very simple database that has two tables: posts (with title and body) and comments (with ForeignKey: post_id and body. When I run rake test I get the following error:

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`

Any help would be appreciated. Thanks.

Sara Tibbetts

This error occurs when you delete a row in a table whose primary key is referenced in another table. You can include ON DELETE CASCADE in your foreign key definition (where you define where the primary key is referenced by another table), or add another delete statement to delete the row referencing the primary key, before doing the delete statement you are currently doing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Syntax error when i run 'rake db:setup' while using ruby 1.9.3

Ruby on Rails: How do I run an automated rake task on Heroku

invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed in Rails

I'm trying to run a rake test ruby / sinatra and its telling me rake aborted! I'm not sure what to do

Rake test error - ActiveRecord::Fixture::FormatError: "Ruby on Rails Tutorial" by MICHAEL HARTL

Ruby on rails error rake db:migrate

I get this error when i run heroku run rake db:migrate in production

Error on jest when I try to run the test

Trying to run a ruby on rails test

PostgreSQL database gets dropped when I run rake db:test:prepare

Error can't load css vs javascript when run rake assets:precompile on rails 4.2.0

YAML syntax error when running "heroku run rake db:migrate" on my Rails app

404 Error When Running Rake Test

Ruby on Rails Rake test - Expected 762146111 to match 762146111

Error when I run auto test with browser. How run it?

Why does Rails fail to run a single rake test?

Rails Rspec - I can't run any test (Postgres error)

I am getting an error when using "rake"

Testing Rake in Rails: Multiple Error Raises Silenced In Test

Need Assistance Solving Rails "bundle exec rake test" Error

Rake aborted! Error even though the file run successfully [Rails]

Exclude external gem warnings when running rake test in Rails

How do I run Rails/Rake from another directory?

What are the key differences between running rake test, and running ruby -Itest test/... (Rails 4.1)

Every RSpec test run requires rake db:test:prepare or equivalent using Rails 4.2.5

Fixnum is deprecated - when I run rake db: seed

Error message when running Rake command in Rails app

ruby on rails tutorial chapter 8 test error

How do I get Rails to load my test envionrment variables when I run tests?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive