小编Rhy*_*s0h的帖子

为什么会出现重复列错误?

active我正在尝试向我的表添加新列students

我跑去rails g migration add_active_to_students active:boolean生成这个迁移:

class AddActiveToStudents < ActiveRecord::Migration[5.0]
  def change
    add_column :students, :active, :boolean, default: true
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我运行时rails db:migrate我收到此错误:

PG::DuplicateColumn:错误:关系“学生”的列“活动”已存在:ALTER TABLE“学生”添加“活动”布尔值默认“t”`

正如您所看到的,实际上没有一activestudents

create_table "students", force: :cascade do |t|
    t.integer  "club_id"
    t.string   "email"
    t.string   "address_line_1"
    t.string   "address_line_2"
    t.string   "city"
    t.string   "state"
    t.integer  "postcode"
    t.string   "phone1"
    t.string   "phone2"
    t.string   "first_name"
    t.string   "last_name"
    t.date     "dob"
    t.datetime "created_at",      null: false
    t.datetime "updated_at",      null: false
    t.string   "picture"
    t.integer  "payment_plan_id"
    t.string   "parent1" …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql activerecord ruby-on-rails

4
推荐指数
1
解决办法
3476
查看次数

标签 统计

activerecord ×1

postgresql ×1

ruby ×1

ruby-on-rails ×1