R
R
Ruslan Galiev2014-08-27 10:29:19
PHP
Ruslan Galiev, 2014-08-27 10:29:19

Why is the Rails gem activerecord-import not saving records to the database?

Hello
I'm using Rail 3.2.13 , gem version 0.3.1. MySQL DB. Gem decided to use it to store a large number of records in the database at a time. About 200 thousand. I decided to test from the console first.

Loading development environment (Rails 3.2.13)
1.9.3-p448 :001 > statuses = [Status.new(name: 'test1'), Status.new(name: 'test2')]
 => [#<Status id: nil, name: "test1", validity: true, created_at: nil, updated_at: nil, info: nil>, #<Status id: nil, name: "test2", validity: true, created_at: nil, updated_at: nil, info: nil>]
1.9.3-p448 :002 > Status.import statuses
  Status Exists (0.3ms)  SELECT 1 AS one FROM `statuses` WHERE `statuses`.`name` = 'test1' LIMIT 1
  Status Exists (0.2ms)  SELECT 1 AS one FROM `statuses` WHERE `statuses`.`name` = 'test2' LIMIT 1
   (0.4ms)  SHOW VARIABLES like 'max_allowed_packet';
  Class Create Many Without Validations Or Callbacks (0.3ms)  INSERT INTO `statuses` (`id`,`name`,`validity`,`created_at`,`updated_at`,`info`) VALUES (NULL,'test1',1,'2014-08-27 11:36:59','2014-08-27 11:36:59',NULL),(NULL,'test2',1,'2014-08-27 11:36:59','2014-08-27 11:36:59',NULL) ON DUPLICATE KEY UPDATE `statuses`.`updated_at`=VALUES(`updated_at`)
 => #<struct ActiveRecord::Import::Result failed_instances=[], num_inserts=1>
1.9.3-p448 :003 > Status.all
  Status Load (0.3ms)  SELECT `statuses`.* FROM `statuses`
 => [#<Status id: 1, name: "test1", validity: true, created_at: "2014-08-27 07:36:59", updated_at: "2014-08-27 07:36:59", info: nil>, #<Status id: 2, name: "test2", validity: true, created_at: "2014-08-27 07:36:59", updated_at: "2014-08-27 07:36:59", info: nil>]

But there are no records in the database. Only the rails see the records :) It seems that I did everything as in the description for the gem. Tell me what's wrong?
update: If after import I create one more record using ActiveRecord:
1.9.3-p448 :011 > Status.create(name: 'test3')
Then all three records will be in the database. Please tell me where the dog is buried? :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fixid, 2016-07-16
@kshnkvn

So here he seems to say that there is no status column in the table

A
Alexey Ukolov, 2016-07-16
@alexey-m-ukolov

Unknown column 'status' in 'where clause'
Which of the words in this sentence can't you translate from English yourself?

V
vsuhachev, 2014-08-27
@vsuhachev

Apparently the rails are looking at the correct database, but you are not. Examine the config/databases.yml file, perhaps there is a clue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question