我创建了一个用户表并将其迁移到Heroku并且运行正常。我试图添加一个管理表,但出了点问题,我不确定发生了什么。用户和管理员表在我的本地环境中工作正常,但是当我将迁移推送到Heroku时,我收到一个错误,即用户表已经创建:
迁移到DeviseCreateUsers(20151119150443) == 20151119150443 DeviseCreateUsers:迁移================================ - create_table(:users)PG :: DuplicateTable:ERROR:relation" users"已存在:CREATE TABLE" users" (" id"串行主键, "电子邮件"字符变化(255)DEFAULT'' NOT NULL, " encrypted_password"字符变化(255)DEFAULT'' NOT NULL, " reset_password_token"字符变化(255), " reset_password_sent_at"时间戳," remember_created_at"时间戳, " sign_in_count"整数DEFAULT 0 NOT NULL," current_sign_in_at" 时间戳," last_sign_in_at"时间戳," current_sign_in_ip"字符 变化(255)," last_sign_in_ip"字符变化(255)," created_at" 时间戳NOT NULL," updated_at"时间戳NOT NULL)rake中止了! StandardError:发生错误,此错误以及稍后的所有迁移 取消:
PG :: DuplicateTable:错误:关系"用户"已存在:CREATE 表"用户" (" id"序列主键,"电子邮件"字符变化(255) 默认'' NOT NULL," encrypted_password"变化的字符(255) 默认'' NOT NULL," reset_password_token"字符变化(255), " reset_password_sent_at"时间戳," remember_created_at"时间戳, " sign_in_count"整数DEFAULT 0 NOT NULL," current_sign_in_at" 时间戳," last_sign_in_at"时间戳," current_sign_in_ip"字符 变化(255)," last_sign_in_ip"字符变化(255)," created_at" 时间戳NOT NULL," updated_at"时间戳NOT NULL) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
当我在本地检查迁移状态时,这就是说:
Status Migration ID Migration Name
--------------------------------------------------
up 20151103020350 Create restaurants
up 20151119150443 Devise create users
up 20160809004949 Devise create admins
heroku上的迁移状态:
Status Migration ID Migration Name
--------------------------------------------------
up 20151030033303 ********** NO FILE **********
up 20151102165952 ********** NO FILE **********
up 20151102170119 ********** NO FILE **********
up 20151103020350 Create restaurants
up 20151103160832 ********** NO FILE **********
up 20151103170143 ********** NO FILE **********
up 20151105172014 ********** NO FILE **********
up 20151114043509 ********** NO FILE **********
down 20151119150443 Devise create users
down 20160809004949 Devise create admins
当我进入Heroku控制台时,它说我有2个用户,因此用户表已迁移,但迁移状态显示为已关闭。
我不介意丢失用户表中的数据,但我真的不想丢失餐馆桌上的数据。不知道如何解决这个问题。
答案 0 :(得分:0)
由于迁移或自定义操作不同,我认为您的数据库已经拥有该表。
通过命令行试试这个,它对我有用!
rake db:drop
rake db:create
rake db:migrate