Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails PG::DuplicateColumn:错误:column";产品标识;“关系的定义”;“用户”;已经存在_Ruby On Rails_Ruby On Rails 5.2 - Fatal编程技术网

Ruby on rails PG::DuplicateColumn:错误:column";产品标识;“关系的定义”;“用户”;已经存在

Ruby on rails PG::DuplicateColumn:错误:column";产品标识;“关系的定义”;“用户”;已经存在,ruby-on-rails,ruby-on-rails-5.2,Ruby On Rails,Ruby On Rails 5.2,我已经看到这个问题贴了好几次了,解决方法总是删除数据库并重新创建它。我的数据库中有数据,因此不想这样做 模式: create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.

我已经看到这个问题贴了好几次了,解决方法总是删除数据库并重新创建它。我的数据库中有数据,因此不想这样做

模式:

create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "product_id"

  end
我的第二个到最后一个迁移文件:

class AddProductIdToUsers < ActiveRecord::Migration[5.2]
  def change
    add_column :users, :product_id, :string
  end
end

但这不起作用。

您的
create\u表
已经在数据库中创建
product\u id

create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "product_id" // <- note this line

  end
create_表“users”,force::cascade do | t|
t、 字符串“email”,默认值:,null:false
t、 字符串“加密的_密码”,默认值:“”,null:false
t、 字符串“重置密码\u令牌”
t、 日期时间“重置密码发送时间”
t、 datetime“记住您创建的时间”
t、 datetime“created_at”,null:false
t、 datetime“更新时间”,null:false

t、 字符串“product_id”//您显示的模式是运行
AddProductIdToUsers
migration时数据库中的实际模式?我不理解这个问题您提供的模式是否代表文件的实际内容?使用
rake db:migrate:status
检查迁移状态。您可能会看到一些带有“无文件”符号的行。从另一个分支复制相应的迁移并回滚
create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string "product_id" // <- note this line

  end