只需登录到Postgres服务器或使用std::find
或任何其他Postgres GUI工具连接数据库,然后在查询窗口中运行以下命令。
pgadmin
这将从您的表中删除所有记录。
,
-
连接到heroku控制台
heroku run rails c -app app_name
-
运行以下代码
ActiveRecord::Base.connection.reset_pk_sequence!('entreprises')
,
没有一种解决方案对我有用,尤其是不能使我删除整个表的解决方案。我选择了另一种方法,即将所有表传递到UUID
并将old_id保存到其他表中:
class ResetIdOfEntreprise < ActiveRecord::Migration[5.1]
def change
add_column :entreprises,:uuid,default: "uuid_generate_v4()",null: false
add_column :entreprises,:old_id,:integer
Entreprise.update_all("old_id=id")
change_table :entreprises do |t|
t.remove :id
t.rename :uuid,:id
end
execute "ALTER TABLE entreprises ADD PRIMARY KEY (id);"
end
end
本文链接:https://www.f2er.com/3167864.html