For some reason, my db: seed does not work when I try to do this with the help of a hero. It works great when I do it locally.
paul@paul-laptop :~/rails_projects/foglift$ heroku rake db:seed rake aborted! PGError: ERROR: null value in column "id" violates not-null constraint : INSERT INTO "metric_records" ("metric_id", "id", "created_at", "updated_at", "value", "school_id", "date") VALUES (1, NULL, '2011-03-18 20:26:39.792164', '2011-03-18 20:26:39.792164', 463866000.0, 1, '2009-01-01') RETURNING "id" (See full trace by running task with --trace) (in /app/5aca24ae-c5a7-4805-a3a1-b2632a5cf558/home)
I am not sure why it is trying to put a zero in the id column, it makes no sense to me.
Here is my seeds.rb file.
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). directory = "db/seed_data/" # Pre-load All Schools School.delete_all path = File.join(directory, "schools.txt") open(path) do |schools| schools.read.each_line do |school| name, city, state, website, tuition, debt = school.chomp.split("|") School.create!(:name => name, :city => city, :state => state, :website => website, :current_tuition => tuition, :current_avg_debt => debt) end end # Pre-load All Dashboards Dashboard.delete_all path = File.join(directory, "dashboards.txt") open(path) do |dashboards| dashboards.read.each_line do |dashboard| name, extra = dashboard.chomp.split("|") Dashboard.create!(:name => name) end end # Pre-load All Metrics Metric.delete_all path = File.join(directory, "metrics.txt") open(path) do |metrics| metrics.read.each_line do |metric| name, dashboard_id, display, source = metric.chomp.split("|") Metric.create!(:name => name, :dashboard_id => dashboard_id, :display => display, :source => source) end end # Pre-load All Metric Records MetricRecord.delete_all path = File.join(directory, "metric_records.txt") open(path) do |values| values.read.each_line do |value| metric_id, value, date_string, school_id = value.chomp.split("|") date_string = '01/01/' << date_string date = Date.strptime(date_string, "%d/%m/%Y") unless date_string.nil? MetricRecord.create!(:metric_id => metric_id, :value => value, :date => date, :school_id => school_id) end end