Closed bhargav-prahladarao closed 5 years ago
Can't figure out why the error popped up.
@bhargav-prahladarao could you please show the "dwords_150720182109.csv"?
Hi workgena,
I am trying to insert one row with below records:
"ನ್ಯೂಹೊರೈಜನ್";"ನ್ಯೂಹೊರೈಜನ್";"1"
This issue resolved after changing csv_headers to csv_headers: ["Word","meaning","is_active","created_by"]
---------- Log extract----------------- Started POST "/admin/words/do_import" for 127.0.0.1 at 2018-07-18 06:57:52 +0530 Processing by Admin::WordsController#do_import as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"t2H7W2Raw5VoOcwcTf/1uHyu6Nwan eOhYJZ/6MKlRs7PqTfnAjcG2DZ8XGd/A5BWLrQ5u8gawQGFDzkzAtIFjA==", "active_admin_impo rt_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0xb526ca4 @tempfile=#<T empfile:/tmp/RackMultipart20180718-3593-1wovaqo.csv>, @original_filename="dwords _150720182109.csv", @content_type="text/csv", @headers="Content-Disposition: for m-data; name=\"active_admin_import_model[file]\"; filename=\"dwords_150720182109 .csv\"\r\nContent-Type: text/csv\r\n">}, "commit"=>"Import"} AdminUser Load (0.9ms) SELECT
admin_users
.* FROMadmin_users
WHEREadmi n_users
.id
= 1 ORDER BYadmin_users
.id
ASC LIMIT 1 (0.7ms) BEGIN (28.4ms) SHOW VARIABLES like 'max_allowedpacket'; Class Create Many Without Validations Or Callbacks (8.4ms) INSERT INTO `word imports(
word,
meaning,
isactive,
created_at,
updated_at) VALUES ('ನ್ಯೂಹೊ ರೈಜನ್','ನ್ಯೂಹೊರೈಜನ್',1,NULL,'2018-07-18 01:27:52',) ON DUPLICATE KEY UPDATE
wor d_imports.
updated_at=VALUES(
updated_at) Mysql2::Error: You have an error in your SQL syntax; check the manual that corre sponds to your MySQL server version for the right syntax to use near ') ON DUPLI CATE KEY UPDATE
word_imports.
updated_at=VALUES(
updated_at)' at line 1: INS ERT INTO
word_imports(
word,
meaning,
isactive,
created_at,
updated_at) VALUES ('ನ್ಯೂಹೊರೈಜನ್','ನ್ಯೂಹೊರೈಜನ್',1,NULL,'2018-07-18 01:27:52',) ON DUPLICATE KEY UPDATE
word_imports.
updated_at=VALUES(
updated_at) (0.5ms) ROLLBACK Error: Mysql2::Error: You have an error in your SQL syntax; check the manual tha t corresponds to your MySQL server version for the right syntax to use near ') O N DUPLICATE KEY UPDATE
word_imports.
updated_at=VALUES(
updated_at)' at line 1: INSERT INTO
word_imports(
word,
meaning,
isactive,
created_at,
update d_at) VALUES ('ನ್ಯೂಹೊರೈಜನ್','ನ್ಯೂಹೊರೈಜನ್',1,NULL,'2018-07-18 01:27:52',) ON DUP LICATE KEY UPDATE
word_imports.
updated_at=VALUES(
updated_at`)-------------admin\word.rb------------
before_filter only: [:do_import] do Thread.current['import.word.CreatedBy'] = current_admin_user.id end active_admin_import validate: false, timestamps: true, resource_class: WordImport, template_object: ActiveAdminImport::Model.new( hint: "file will be imported with such header format: 'Word','Meaning','isactive'", csv_headers: ["word","meaning","isactive"], csv_options: { col_sep: ";",row_sep: nil, quote_char: '"' }), before_batch_import: ->(importer) { importer.csv_lines.map{|line| line << Thread.current['import.bus.CreatedBy'] }}, after_import: proc{ Word.transaction do Word.connection.execute("INSERT INTO words (Word, Meaning, CreatedDate, UpdatedDate, IsActive ) (SELECT word, meaning, created_at, updated_at, isactive FROM word_imports)") end }
------------------model---------- WordImport
Word