首页 文章

Heroku上的表重复错误 - 表已经存在,但迁移表示向下 - 在本地工作

提问于
浏览
1

我创建了一个用户表并将其迁移到Heroku,它工作正常 . 我试图添加一个管理表但出了点问题,我不确定发生了什么 . 用户和管理员表在我的本地环境中工作正常,但是当我将迁移推送到Heroku时,我收到一个错误,即用户表已经创建:

迁移到DeviseCreateUsers(20151119150443)== 20151119150443 DeviseCreateUsers:迁移================================ - create_table(:用户)PG :: DuplicateTable:错误:关系“用户”已存在:CREATE TABLE“users”(“id”串行主键,“email”字符变化(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”timestamp,“last_sign_in_at”timestamp,“current_sign_in_ip”字符变化(255),“last_sign_in_ip”字符变化(255),“created_at”时间戳NOT NULL,“updated_at”时间戳NOT NULL)rake中止! StandardError:发生错误,此以及所有后续迁移都已取消:PG :: DuplicateTable:错误:关系“users”已存在:CREATE TABLE“users”(“id”串行主键,“email”字符变化(255)DEFAULT ''NOT NULL,“encrypted_password”字符变化(255)DEFAULT''NOT NULL,“reset_password_token”字符变化(255),“reset_password_sent_at”timestamp,“remember_created_at”时间戳,“sign_in_count”整数DEFAULT 0 NOT NULL,“current_sign_in_at” timestamp,“last_sign_in_at”timestamp,“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个用户,因此迁移了用户表,但迁移状态显示为已关闭 .

我不介意丢失用户表中的数据,但我真的不想丢失餐馆表中的数据 . 不知道如何解决这个问题 .

1 回答

  • 0

    由于迁移或自定义操作不同,我认为您的数据库已经拥有该表 .

    通过命令行尝试这个,它对我有用!

    rake db:drop
    rake db:create
    rake db:migrate
    

相关问题