class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration
  def change
    Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items|
      line_items.each do |line_item|
        next if line_item.variant.nil?
        next if line_item.variant.product.nil?
        next if line_item.product.nil?
        line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
      end
    end
  end
end

class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration
  def change
  	Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items|
  	  line_items.each do |line_item|
        line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
      end
    end
  end
end

--- 
+++ 
@@ -1,7 +1,10 @@
 class MigrateTaxCategoriesToLineItems < ActiveRecord::Migration
   def change
-  	Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items|
-  	  line_items.each do |line_item|
+    Spree::LineItem.includes(:variant => { :product => :tax_category }).find_in_batches do |line_items|
+      line_items.each do |line_item|
+        next if line_item.variant.nil?
+        next if line_item.variant.product.nil?
+        next if line_item.product.nil?
         line_item.update_column(:tax_category_id, line_item.product.tax_category_id)
       end
     end
Add exceptions for blank records in tax categories migration

Fixes #4204
