Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition> #10613

Closed
mountriv99 opened this Issue · 33 comments
@mountriv99

Got an undefined method 'sql_type' error when I tried to run my tests after upgrading from an alpha version of Rails 4 to Rails 4.0 rc1

FULL TRACE:

eric@ubuntu:~/apps/pc$ bundle exec rake test:models --trace
** Invoke test:models (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge 
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:schema:load
rake aborted!
undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition:0xa524cac>
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/quoting.rb:106:in `type_cast'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/cast.rb:76:in `block in array_to_string'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/cast.rb:71:in `map'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/cast.rb:71:in `array_to_string'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/quoting.rb:35:in `quote'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_statements.rb:698:in `add_column_options!'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:168:in `add_column_options!'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:31:in `add_column_options!'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:135:in `visit_ColumnDefinition'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:14:in `visit_ColumnDefinition'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:116:in `accept'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:142:in `block in visit_TableDefinition'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:142:in `map'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:142:in `visit_TableDefinition'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:116:in `accept'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/abstract/schema_statements.rb:190:in `create_table'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:622:in `block in method_missing'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:594:in `block in say_with_time'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/benchmark.rb:280:in `measure'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:594:in `say_with_time'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/migration.rb:614:in `method_missing'
/home/eric/apps/pc/db/schema.rb:233:in `block in <top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/schema.rb:42:in `instance_eval'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/schema.rb:42:in `define'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/schema.rb:62:in `define'
/home/eric/apps/pc/db/schema.rb:14:in `<top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:222:in `load'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:222:in `block in load'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:222:in `load'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/railties/databases.rake:253:in `block (3 levels) in <top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/railties/databases.rake:326:in `block (3 levels) in <top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0.rc1/lib/active_record/railties/databases.rake:316:in `block (3 levels) in <top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/home/eric/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/home/eric/.rbenv/versions/1.9.3-p327/bin/rake:23:in `load'
/home/eric/.rbenv/versions/1.9.3-p327/bin/rake:23:in `<main>'
Tasks: TOP => db:schema:load
@tenderlove
Owner

Can you provide your schema.rb (or sql) file for us?

@mountriv99

Posted from the wrong branch before, updated with the correct schema file:

ActiveRecord::Schema.define(version: 20130513073916) do

    create_table "admins", force: true do |t|
      t.integer  "school_id",                                  null: false
      t.string   "title",           limit: 4,                  null: false
      t.string   "first_name",      limit: 50,                 null: false
      t.string   "last_name",       limit: 50,                 null: false
      t.string   "email",           limit: 50,                 null: false
      t.string   "password_digest"
      t.boolean  "master",                     default: false
      t.integer  "status",          limit: 2,                  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "admins", ["email"], name: "index_admins_on_email", unique: true
    add_index "admins", ["first_name", "last_name"], name: "index_admins_on_first_name_and_last_name"
    add_index "admins", ["last_name", "first_name"], name: "index_admins_on_last_name_and_first_name"
    add_index "admins", ["school_id"], name: "index_admins_on_school_id"

    create_table "announcements", force: true do |t|
      t.integer  "school_id",                      null: false
      t.integer  "updater_id",                     null: false
      t.string   "updater_type", default: "Admin"
      t.boolean  "published",    default: true,    null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.hstore   "title",                          null: false
      t.hstore   "content",                        null: false
    end

    add_index "announcements", ["published"], name: "index_announcements_on_published"
    add_index "announcements", ["school_id"], name: "index_announcements_on_school_id"
    add_index "announcements", ["updated_at"], name: "index_announcements_on_updated_at"
    add_index "announcements", ["updater_type", "updater_id"], name: "index_announcements_on_updater_type_and_updater_id"

    create_table "assessments", force: true do |t|
      t.integer  "course_id"
      t.string   "name",         limit: 80,               null: false
      t.float    "weight",                  default: 1.0, null: false
      t.date     "assessed_on"
      t.float    "full_score",                            null: false
      t.hstore   "scores"
      t.float    "total_scores",            default: 0.0, null: false
      t.integer  "scores_count",            default: 0,   null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "assessments", ["assessed_on"], name: "index_assessments_on_assessed_on"
    add_index "assessments", ["course_id"], name: "index_assessments_on_course_id"

    create_table "attendances", force: true do |t|
      t.integer  "school_id",                                  null: false
      t.integer  "course_id",                                  null: false
      t.integer  "student_id",                                 null: false
      t.integer  "updater_id",                                 null: false
      t.string   "updater_type",           default: "Teacher"
      t.integer  "status",       limit: 2,                     null: false
      t.date     "taken_on",                                   null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "attendances", ["course_id", "student_id", "taken_on"], name: "index_attendances_on_course_id_and_student_id_and_taken_on", unique: true
    add_index "attendances", ["course_id"], name: "index_attendances_on_course_id"
    add_index "attendances", ["school_id"], name: "index_attendances_on_school_id"
    add_index "attendances", ["student_id"], name: "index_attendances_on_student_id"
    add_index "attendances", ["taken_on"], name: "index_attendances_on_taken_on"
    add_index "attendances", ["updated_at"], name: "index_attendances_on_updated_at"

    create_table "courses", force: true do |t|
      t.integer  "school_id",                                         null: false
      t.string   "code",                      limit: 20
      t.date     "start_date",                                        null: false
      t.date     "end_date",                                          null: false
      t.integer  "teachers_count",            limit: 2,  default: 0,  null: false
      t.integer  "students_count",            limit: 2,  default: 0,  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "performance_indicator_ids",            default: [], null: false, array: true
      t.hstore   "name",                                              null: false
      t.string   "seating_plan",                         default: [],              array: true
    end

    add_index "courses", ["code"], name: "index_courses_on_code"
    add_index "courses", ["end_date"], name: "index_courses_on_end_date"
    add_index "courses", ["performance_indicator_ids"], name: "index_courses_on_performance_indicator_ids"
    add_index "courses", ["school_id"], name: "index_courses_on_school_id"
    add_index "courses", ["start_date"], name: "index_courses_on_start_date"

    create_table "devices", force: true do |t|
      t.integer  "user_id",              null: false
      t.string   "user_type",            null: false
      t.integer  "os",         limit: 2, null: false
      t.string   "uuid",                 null: false
      t.string   "token"
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "devices", ["os", "uuid"], name: "index_devices_on_os_and_uuid"
    add_index "devices", ["user_id", "user_type"], name: "index_devices_on_user_id_and_user_type"

    create_table "feedbacks", force: true do |t|
      t.integer  "teacher_id", null: false
      t.integer  "course_id",  null: false
      t.integer  "student_id", null: false
      t.text     "message",    null: false
      t.date     "given_on",   null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "feedbacks", ["course_id"], name: "index_feedbacks_on_course_id"
    add_index "feedbacks", ["given_on"], name: "index_feedbacks_on_given_on"
    add_index "feedbacks", ["student_id"], name: "index_feedbacks_on_student_id"
    add_index "feedbacks", ["teacher_id"], name: "index_feedbacks_on_teacher_id"

    create_table "groups", force: true do |t|
      t.integer  "course_id",                              null: false
      t.string   "name",           limit: 30, default: "", null: false
      t.string   "image"
      t.integer  "students_count", limit: 2,  default: 0,  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "groups", ["course_id"], name: "index_groups_on_course_id"

    create_table "homeworks", force: true do |t|
      t.integer  "course_id",               null: false
      t.string   "description", limit: 250, null: false
      t.date     "assigned_on",             null: false
      t.date     "due_on",                  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "homeworks", ["assigned_on"], name: "index_homeworks_on_assigned_on"
    add_index "homeworks", ["due_on"], name: "index_homeworks_on_due_on"

    create_table "klasses", force: true do |t|
      t.integer  "school_id",                            null: false
      t.integer  "students_count", limit: 2, default: 0, null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "teachers_count", limit: 2, default: 0, null: false
      t.hstore   "name",                                 null: false
    end

    add_index "klasses", ["school_id"], name: "index_klasses_on_school_id"

    create_table "parents", force: true do |t|
      t.string   "title",            limit: 4,                 null: false
      t.string   "first_name",       limit: 50,                null: false
      t.string   "last_name",        limit: 50,                null: false
      t.string   "email",            limit: 50,                null: false
      t.string   "password_digest"
      t.integer  "status",           limit: 2,                 null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "preferred_locale", limit: 10, default: "en", null: false
    end

    add_index "parents", ["email"], name: "index_parents_on_email", unique: true

    create_table "performance_indicators", force: true do |t|
      t.hstore   "name",                   null: false
      t.hstore   "description"
      t.string   "icon",        limit: 30, null: false
      t.integer  "value",       limit: 2,  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "performance_indicators", ["value"], name: "index_performance_indicators_on_value"

    create_table "points", force: true do |t|
      t.integer  "teacher_id",                         null: false
      t.integer  "course_id",                          null: false
      t.integer  "student_id",                         null: false
      t.integer  "value",                    limit: 2, null: false
      t.date     "given_on",                           null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "performance_indicator_id",           null: false
    end

    add_index "points", ["course_id"], name: "index_points_on_course_id"
    add_index "points", ["given_on"], name: "index_points_on_given_on"
    add_index "points", ["performance_indicator_id"], name: "index_points_on_performance_indicator_id"
    add_index "points", ["student_id"], name: "index_points_on_student_id"
    add_index "points", ["teacher_id"], name: "index_points_on_teacher_id"

    create_table "relationships", force: true do |t|
      t.integer  "parent_id",             null: false
      t.integer  "student_id",            null: false
      t.string   "relation",   limit: 30, null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "relationships", ["parent_id", "student_id"], name: "index_relationships_on_parent_id_and_student_id", unique: true
    add_index "relationships", ["parent_id"], name: "index_relationships_on_parent_id"
    add_index "relationships", ["relation"], name: "index_relationships_on_relation"
    add_index "relationships", ["student_id"], name: "index_relationships_on_student_id"

    create_table "reminders", force: true do |t|
      t.integer  "course_id",              null: false
      t.string   "content",    limit: 250, null: false
      t.date     "created_on",             null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "reminders", ["course_id"], name: "index_reminders_on_course_id"
    add_index "reminders", ["created_on"], name: "index_reminders_on_created_on"

    create_table "schools", force: true do |t|
      t.string   "name",           limit: 150,                  null: false
      t.string   "code",           limit: 30,                   null: false
      t.hstore   "address",                                     null: false
      t.hstore   "contact",                                     null: false
      t.integer  "admins_count",   limit: 2,   default: 0,      null: false
      t.integer  "teachers_count", limit: 2,   default: 0,      null: false
      t.integer  "students_count", limit: 2,   default: 0,      null: false
      t.integer  "courses_count",  limit: 2,   default: 0,      null: false
      t.integer  "status",         limit: 2,   default: 0,      null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "time_zone",      limit: 40,                   null: false
      t.string   "locales",                    default: ["en"], null: false, array: true
    end

    add_index "schools", ["code"], name: "index_schools_on_code", unique: true
    add_index "schools", ["name"], name: "index_schools_on_name"

    create_table "student_courses", force: true do |t|
      t.integer  "student_id", null: false
      t.integer  "course_id",  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "student_courses", ["course_id"], name: "index_student_courses_on_course_id"
    add_index "student_courses", ["student_id", "course_id"], name: "index_student_courses_on_student_id_and_course_id", unique: true
    add_index "student_courses", ["student_id"], name: "index_student_courses_on_student_id"

    create_table "student_groups", force: true do |t|
      t.integer  "student_id", null: false
      t.integer  "group_id",   null: false
      t.integer  "course_id",  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "student_groups", ["course_id"], name: "index_student_groups_on_course_id"
    add_index "student_groups", ["group_id"], name: "index_student_groups_on_group_id"
    add_index "student_groups", ["student_id", "course_id"], name: "index_student_groups_on_student_id_and_course_id", unique: true
    add_index "student_groups", ["student_id"], name: "index_student_groups_on_student_id"

    create_table "student_klasses", force: true do |t|
      t.integer  "student_id", null: false
      t.integer  "klass_id",   null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "student_klasses", ["klass_id"], name: "index_student_klasses_on_klass_id"
    add_index "student_klasses", ["student_id", "klass_id"], name: "index_student_klasses_on_student_id_and_klass_id", unique: true
    add_index "student_klasses", ["student_id"], name: "index_student_klasses_on_student_id"

    create_table "students", force: true do |t|
      t.integer  "school_id",                              null: false
      t.string   "number",          limit: 20,             null: false
      t.string   "gender",          limit: 1
      t.date     "dob"
      t.string   "avatar"
      t.string   "password_digest"
      t.string   "parent_code",     limit: 10
      t.integer  "parents_count",   limit: 2,  default: 0, null: false
      t.integer  "status",          limit: 2,              null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "klass_id"
      t.hstore   "first_name",                             null: false
      t.hstore   "last_name",                              null: false
    end

    add_index "students", ["school_id", "klass_id"], name: "index_students_on_school_id_and_klass_id"
    add_index "students", ["school_id", "number"], name: "index_students_on_school_id_and_number"
    add_index "students", ["school_id"], name: "index_students_on_school_id"

    create_table "teacher_courses", force: true do |t|
      t.integer  "teacher_id", null: false
      t.integer  "course_id",  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "teacher_courses", ["course_id"], name: "index_teacher_courses_on_course_id"
    add_index "teacher_courses", ["teacher_id", "course_id"], name: "index_teacher_courses_on_teacher_id_and_course_id", unique: true
    add_index "teacher_courses", ["teacher_id"], name: "index_teacher_courses_on_teacher_id"

    create_table "teacher_klasses", force: true do |t|
      t.integer  "teacher_id", null: false
      t.integer  "klass_id",   null: false
      t.datetime "created_at"
      t.datetime "updated_at"
    end

    add_index "teacher_klasses", ["klass_id"], name: "index_teacher_klasses_on_klass_id"
    add_index "teacher_klasses", ["teacher_id", "klass_id"], name: "index_teacher_klasses_on_teacher_id_and_klass_id", unique: true
    add_index "teacher_klasses", ["teacher_id"], name: "index_teacher_klasses_on_teacher_id"

    create_table "teachers", force: true do |t|
      t.integer  "school_id",                  null: false
      t.string   "title",           limit: 4,  null: false
      t.string   "first_name",      limit: 50, null: false
      t.string   "last_name",       limit: 50, null: false
      t.string   "email",           limit: 50, null: false
      t.string   "password_digest"
      t.integer  "status",          limit: 2,  null: false
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "code",            limit: 50, null: false
      t.integer  "klass_id"
    end

    add_index "teachers", ["first_name", "last_name"], name: "index_teachers_on_first_name_and_last_name"
    add_index "teachers", ["last_name", "first_name"], name: "index_teachers_on_last_name_and_first_name"
    add_index "teachers", ["school_id", "code"], name: "index_teachers_on_school_id_and_code", unique: true
    add_index "teachers", ["school_id", "email"], name: "index_teachers_on_school_id_and_email", unique: true
    add_index "teachers", ["school_id", "klass_id"], name: "index_teachers_on_school_id_and_klass_id"
    add_index "teachers", ["school_id"], name: "index_teachers_on_school_id"

end
@mountriv99

Line 233 of scheme.rb is just

create_table "schools", force: true do |t|

I can't spot anything unusual with that line or that block.....

@mountriv99

I found out the problem had something to do with the default value in the string array column.

This is what I have in my migration:

t.string :locales, :array => true, :null => false, :default => '{"en"}'

But in schema.rb the default value became:

t.string "locales", default: ["en"], null: false, array: true

It works if i change that into this:

t.string "locales", default: '{"en"}', null: false, array: true
@neerajdotname
Collaborator

@mountriv99 I have not looked at code but it seems the default value should be an array for a column which is being marked as an array. May be an exception should be raised in this case if the default value is not an array.

@mountriv99

@neerajdotname sorry I'm not sure I understand you correctly. The default values shown above are all arrays, except that when schema.rb was generated, the postgresql array ('{"en"}') was turned into a ruby array (["en"]). Now my migration ran without a problem, even the table description looks ok (see below), and my application seems to be running fine in development. But the problem is (I'm guessing) that when I run my tests, since it loads from schema.rb, it doesn't like the ruby array and throws an exception.

Table description:
Table "public.schools"
Column | Type | Modifiers
----------------+-----------------------------+------------------------------------------------------
id | integer | not null default nextval('schools_id_seq'::regclass)
name | character varying(150) | not null
code | character varying(30) | not null
locales | character varying(255)[] | not null default '{en}'::character varying[]
--More--

@neerajdotname
Collaborator

@mountriv99 thanks for the clarification. I'll take a look at this issue tomorrow.

@mountriv99

@neerajdotname cool, thanks!

@neerajdotname
Collaborator

@mountriv99 I have a fix here https://github.com/neerajdotname/rails/compare/10613 .

Can you try my branch and lemme know if this fixes your problem.

gem 'rails', github: 'neerajdotname/rails', branch: 10613

I'll write test etc if this works for you.

@mountriv99

@neerajdotname
the string arrays seem okay now, but now i'm having problem with the integer arrays

This is what I'm getting:
PG::Error: ERROR: column "performance_indicator_ids" is of type integer[] but default expression is of type integer
HINT: You will need to rewrite or cast the expression.
: CREATE TABLE "courses" ("id" serial primary key, "school_id" integer NOT NULL, "name" hstore NOT NULL, "code" character varying(20) NOT NULL, "seating_plan" character varying(255)[] DEFAULT '{}', "start_date" date NOT NULL, "end_date" date NOT NULL, "performance_indicator_ids" integer[] DEFAULT 0 NOT NULL, "teachers_count" smallint DEFAULT 0 NOT NULL, "students_count" smallint DEFAULT 0 NOT NULL, "created_at" timestamp, "updated_at" timestamp)

Notice the line:

  • "performance_indicator_ids" integer[] DEFAULT 0 NOT NULL where the default value became 0 instead of something like "{}"

The corresponding line in schema.rb:

  • t.integer "performance_indicator_ids", default: "{}", null: false, array: true

How the same line looked like before the patch:

  • t.integer "performance_indicator_ids", default: [], null: false, array: true

Seems like the default value "{}", since the column is of type integer, got casted to an integer. And "{}".to_i = 0, and postgres doesn't understand DEFAULT 0 for a column of type integer[].

As a side note, this is how I specify the default values in my migration

  • for string arrays, :default => "{a, b, c}"
  • for integer arrays, :default => [1, 2, 3]

And this used to work before I upgraded to 4.0.0.rc1
I found articles such as this one (http://reefpoints.dockyard.com/ruby/2012/09/18/rails-4-sneak-peek-postgresql-array-support.html) that tells me to do :default => '{1}' for integer arrays as well, but that never worked for me (would get the same exception as above).
I'm actually pretty new to postgres, so maybe I got the syntax wrong?

@neerajdotname
Collaborator

@mountriv99 for integer array the default must be in ruby integer. Like this

    create_table :users do |t|
      t.string :locales, :array => true, :null => false, :default => '{en}'
      t.integer :points, :array => true, :null => false, :default => [1,2,3]
    end

Can you try that ?

@mountriv99

@neerajdotname

That's what I have in my migration file, and that's why the migration was fine. But when I tried to run the tests, since it loads from schema.rb, and the new patch turned my default ruby array ([]) into '{}' like so:

  • t.integer "performance_indicator_ids", default: "{}", null: false, array: true

and the tests would not run

@mountriv99

To sum up, let's say I have this in my migration:

create_table :users do |t|
  t.string :locales, :array => true, :null => false, :default => '{en}'
  t.integer :points, :array => true, :null => false, :default => [1,2,3]
end

Before your fix, the schema.rb becomes:

create_table "users", force: true do |t|
  t.string "locales", default: ["en"], null: false, array: true
  t.integer "points", default: [1,2,3], null: false, array: true
end

and the string array (locales) would fail.

After your fix, the schema.rb becomes:

create_table "users", force: true do |t|
  t.string "locales", default: '{en}', null: false, array: true
  t.integer "points", default: '{1,2,3}', null: false, array: true
end

and the integer array (points) would fail.

@neerajdotname
Collaborator

@mountriv99 I have pushed a fix to that branch So do 'bundle update' and try again.

This is my migration

    create_table :users do |t|
      t.string :locales, :array => true, :null => false, :default => '{en}'
      t.integer :points, :array => true, :null => false, :default => [1,2,3]
    end

and now this is schema.rb I'm getting

  create_table "users", force: true do |t|
    t.string  "locales", default: "{en}",    null: false, array: true
    t.integer "points",  default: [1, 2, 3], null: false, array: true
  end
@mountriv99

@neerajdotname Looks good! Thanks for the work!

@milgner

Just tried your branch but still get the same exception as soon as I put any column with a :default clause in my schema.rb.

Update: just realized that the JRuby/JDBC version of the adapter of course needs to be adapted separetely. Never mind, I'll fix it accordingly!

@neerajdotname
Collaborator

@milgner can you paste your migration files so that I can take a look at them.

@milgner

Problem has been fixed after updating to latest activerecord-jdbc-adapter - sorry for the confusion!

@senny
Owner

@neerajdotname what is the status on this one?

@milgner

Should be fixed, as far as I can see. Probably the issue can be closed?

@senny
Owner

@milgner thanks, I'm closing. Please report if there is something left to do.

@senny senny closed this
@nfm

@senny I think this is still an issue.

I just hit the same problem as @mountriv99 with a string array column with a default value under Rails 4 and MRI.

I haven't tried @neerajdotname's branch yet, but I believe it hasn't been merged into rails/rails at this point in time, and I can't find a pull request for it.

Can anyone confirm this is still an issue without a PR/merged fix?

@senny
Owner

let's wait for @neerajdotname to jump in.

@neerajdotname
Collaborator

@senny @nfm I think this issue is still there. However I'm not sure if my fix is the best solution. That is why I did not send PR although I think my fix does fix the problem.

I'll take a look at it in next couple of days. Thanks.

@senny senny reopened this
@rafaelfranca

@neerajdotname had you send the pull request? If not please send so we can discuss the solution.

@neerajdotname
Collaborator

@nfm sent a PR. #12519 . Can you try and lemme know if this fixes the problem you are having ? Thanks.

@sergiobayona

Any word on a solution? I'm having this exact same issue.

@milgner

@sergiobayona what Ruby interpreter and gem versions do you use?

@sergiobayona

@milgner ruby 2.1.1p76, rails 4.1.0.rc1, pg 0.17.1

It fails when it hits this point on the schema.rb:

t.text "business_days", default: ["1", "2", "3", "4", "5"], null: false, array: true

Error:

undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition:0x007f984c3a2d70>
@lukesteensen

This is definitely still an issue in 4.1.0rc2.

This line in a migration fails:

t.string :tags, array: true, default: ["testing"]

With this error:

undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition:0x007f8b84954f68>

It can be fixed by changing it to use a postgres array literal for the default value:

t.string :tags, array: true, default: "{testing}"

However, after running that migration, the following is added to schema.rb:

t.string :tags, array: true, default: ["testing"]

Because it switches back to the ruby representation of the array, running rake db:schema:load now fails with the same error.

@lukesteensen lukesteensen referenced this issue from a commit in lukesteensen/rails
@lukesteensen lukesteensen remove calls to sql_type on pg columns
fixes postgres array default values, issue #10613
faf1869
@lukesteensen lukesteensen referenced this issue from a commit in lukesteensen/rails
@lukesteensen lukesteensen remove calls to sql_type on pg columns
fixes postgres array default values, issue #10613
666a9df
@rubiii

same issue here with rails 4.0.2 running on ruby 2.1.1p76.
will this be fixed in 4.1.0? let me know if i can do anything to help you out.

@lukesteensen

I'm pretty sure I have this fixed in #14509. The implementation can probably be improved, but I also have a simple failing test, which should help regardless.

@lukesteensen lukesteensen referenced this issue from a commit in lukesteensen/rails
@lukesteensen lukesteensen fix error on non empty default for pg array column
fixes #10613
c7982ef
@lukesteensen lukesteensen referenced this issue from a commit in lukesteensen/rails
@lukesteensen lukesteensen fix bug on non empty defaults for pg array columns
fixes #10613
78e4862
@vol7ron

This may be closed, but I've noticed a similar issue when trying to get the sql_type of a timestamp field.

I was trying to build a UNION query off the raw_connection, in which case I needed to typecast NULLs. I don't know if the error occurs with all timestamps, but with the one in my table it has the same error:

undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition

And this is what I used to produce it:

result.all.column_types['<datetime_fieldname>'].sql_type
  • result is an ActiveR* variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.