1

when running my rspec test I am getting an error very similar to the one in this post, but the author's solution is not working for me. The error:

Mysql2::Error: Field 'target_id' doesn't have a default value: INSERT INTO `illegal_links` (`url`, `status`, `time_found`, `track_id`, `user_id`, `created_at`, `updated_at`) VALUES ('http://www.whatever.com', 'new', '2013-12-19 17:25:52.000000', 3212, 6980, '2017-09-27 15:40:38.121788', '2017-09-27 15:40:38.121788')

The 'illegal link' factory calls the target factory along with two others, but target_id is the only one that throws an error:

factory :illegal_link do
  url "http://www.whatever.com"
  status "new"
  time_found "2013-12-19 17:25:52"
  url_type "file"
  track
  target
  user

What I really don't understand is that removing the call to the target factory and instead using 'target_id 1' gets the same error. Creating 'targets' from the console each get a new id, so it is not a missing auto increment in mysql.

I'm running rails 4.2.0, ruby 2.3.0, rspec-rails 3.6.0, factory_girl 4.8.0, and mysql2 0.3.21

Any ideas would be appreciated, thanks.

Edit: here is the schema for the target_id on the illegal_links tables:

t.integer  "target_id",      limit: 4,          null: false
add_index "illegal_links", ["target_id"], name: "target_id", using: :btree
Sawyer Merchant
  • 1,243
  • 2
  • 12
  • 21
  • How is the `track_id` column defined in the schema? Can you include the schema.rb so that we can exclude some pontential causes? – max Sep 27 '17 at 16:39
  • Hi Max, thanks for taking a look. I've added the schema info for the `target_id` since it is the one throwing the error, but `track_id` is defined the same way. – Sawyer Merchant Sep 27 '17 at 17:22

0 Answers0