DBã«å¶ç´ãå¼µã ãã®ãããªãã¼ãã«ããã£ãã¨ãã¾ãã CREATE TABLE products( id serial NOT NULL, code varchar NOT NULL, price integer NOT NULL CHECK (price > 0), CONSTRAINT pk_products PRIMARY KEY (id) ); åã«ã©ã ã«NOT NULLå¶ç´ priceã«CHECKå¶ç´ ã¨ãã2ç¹ãé¤ãã°ãrails g migrationã§ä½ããããã®ã¨åãã ã¨æãã¾ãã ãã®ãã¼ãã«ã«ããã¦ã ActiveRecord::Base.transaction do CSV.foreach(csv_path) do |row| code, price = row[0], row[1] Product.create!(code: code, price: price
{{#tags}}- {{label}}
{{/tags}}