开发者

Ruby on Rails Testing with MySQL

开发者 https://www.devze.com 2023-03-18 10:16 出处:网络
I\'m trying to test with Ruby on Rails with a MySQL database. When attempting to run the test each test fails with the same reason:

I'm trying to test with Ruby on Rails with a MySQL database. When attempting to run the test each test fails with the same reason:

ActiveRecord::StatementInvalid: Mysql::Error: Table 'db_test.session_cleaners' doesn't exist: DELETE FROM `session_cleaners`

I created a session_cleaners table with a primary key and am now getting this error:

ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '0' for key 'PRIMARY': INSERT INTO `session_cleaners` () VALUES ()

I doubt I need the session_cleaners开发者_运维问答 table but I'm not sure what else to do. Any help would be appreciated.

Thanks


You should run the migrations and prepare the test database:

bundle exec rake db:migrate
bundle exec rake db:test:prepare

This will take care of everything provided you have valid migrations.

You'd better read the guides - there's plenty of information that people don't even realise.


There were two things that I did to fix this:

  1. Update the MySQL gem so that I was using 2.7. I'm on Ruby 1.8.6/Rails 2.3.10 so this gem was required
  2. Create a session_cleaner table with one field: id. The id is not a primary key and does allow null.

These two things made it so I could prepare the test environment

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号