“PG DuplicateTable:错误关系“产品”已存在”- Heroku db:迁移尝试

2024-05-07

Rails 菜鸟尝试将 DB 迁移到 Heroku。请原谅这个错误消息的多汁性,但我认为将其全部包含在内可能很重要。我不知道为什么会发生这种情况,也不知道这意味着什么。我的架构中只有一张产品表和一张创建产品迁移表。

Migrating to CreateProducts (20140804010848)
== 20140804010848 CreateProducts: migrating ===================================
-- create_table(:products)
PG::DuplicateTable: ERROR:  relation "products" already exists
: CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "price" float, "description" text, "image" character varying(255), "color" character varying(255), "created_at" timestamp, "updated_at" timestamp) 
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable: ERROR:  relation "products" already exists
: CREATE TABLE "products" ("id" serial primary key, "name" character varying(255), "price" float, "description" text, "image" character varying(255), "color" character varying(255), "created_at" timestamp, "updated_at" timestamp) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in `create_table'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/app/db/migrate/20140804010848_create_products.rb:3:in `change'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

转到 Heroku Rails 控制台并通过运行以下命令删除产品(假设它们不包含任何数据)表:

ActiveRecord::Migration.drop_table(:products)

并重新运行迁移。

或者只是从 db/migration 删除创建产品表的迁移文件

这也会起作用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“PG DuplicateTable:错误关系“产品”已存在”- Heroku db:迁移尝试 的相关文章

  • Ruby on Rails:如何检查复数形式和单一形式的名称

    我用命令创建了一个匿名模型 rails g model Anonymous section id integer aid string fake bool active bool 但迁移中的表名称为匿名 class CreateAnonym
  • 如何在 postgresql 中使用“时间”字段按小时分组?

    我有一张带有一列的桌子ctime类型的time without time zone cdate ctime 2016 12 24 12 02 17 2016 12 24 12 02 32 2016 12 24 12 03 00 2016 1
  • 为什么PostgresQL查询性能随着时间的推移而下降,但重建索引时又恢复了

    根据这个page http www postgresql org docs current static indexes examine html在手册中 indexes don t need to be maintained 然而 我们运
  • Ruby on Rails:如何设计 SaaS 基础设施?

    我正在构建一个 Rails 3 应用程序 计划将其作为基于订阅的 SaaS 软件即服务 产品提供 基本上 我希望用户能够点击我的 注册 页面 创建一个新帐户 并立即开始使用该软件 我想要实现的一个很好的例子是 http www gethar
  • Ruby on Rails 中的枚举

    我是一名 C 程序员 我正在研究 ruby on Rails 但我可能在心态或其他方面遇到了一些麻烦 我有一个投票对象 该对象可以是赞成 中立或反对 我通常会让投票对象有一个像这样的字段 private VoteEnum voteEnum
  • 错误:没有名为 psycopg2.extensions 的模块

    我正在尝试为我的 django 项目设置一个 PostgreSQL 数据库 由于对上一个问题的答复 我相信我现在已经完成了为 django 项目设置 postgreSQL 数据库时出现问题 https stackoverflow com q
  • Postgresql,选择一个“假”行

    在 Postgres 8 4 或更高版本中 获取默认填充的一行数据的最有效方法是什么没有实际创建行 例如 作为交易 伪代码 create table mytable id serial PRIMARY KEY NOT NULL parent
  • Rails 创建 schema_migrations - Mysql2::Error: 指定的键太长

    我正在使用Rails 3 2 6和Mysql 6 0 9 但我在MySQL 5 2 25上有完全相同的错误 当我创建新数据库时 rake db create 然后当我尝试加载架构时 rake schema load 我收到此错误 Mysql
  • 通过 JDBC 与 CLI 使用 MIT Kerberos 连接到 PostgreSQL 9.4 时出错

    我已经使用 MIT Kerberos 5 设置了 PostgreSQL 9 4 并且可以使用 psql 在 CLI 上连接 提交指纹后 我的委托人是 bgiles postgres REALM pg hba conf 有 host all
  • 无法安装 RMagick 0.0.0。找不到 Magick 配置

    我正在运行 debian 服务器并在一段时间后升级了所有软件包 apt get update apt get upgrade apt get distro upgrade 然后 rmagick 不再工作了 因为 imagemagick 被更
  • Pycharm错误:配置不正确

    在我的 DEV 计算机意外关闭后 当返回 Pycharm 项目时 我注意到我正在编辑的 Django 视图文件 有 700 多行 发生这种情况时 它完全是空的 我设法从备份中恢复它 那里没有损失 尝试调试时出现问题 它返回此错误 不正确配置
  • 按共同关联的数量排序 (Rails)

    背景 我有帖子和用户 并且都有很多社区 客观的 对于任何给定的用户 我想返回一个帖子集合 按该帖子与该用户有共同社区的数量排序 具有更多共同社区的帖子位于更高的位置 我当前的尝试 使用排序方法 有效 Post includes commun
  • 防止Rails Turbolinks导致Google地图JS多次执行

    我目前正在开发 Rails 应用程序 但出现以下错误 您已在此页面上多次包含 Google Maps API 这可能会导致意外错误 经过一番研究后 我发现 Turbolinks 导致了这个问题 当 的时候link to单击后 Google
  • Rails 4 不更新嵌套属性

    Issue 代替updating嵌套属性 它们正在created当我点击现有的嵌套属性之上 update相关的行动features controller rb 可能的原因 我认为问题在于我对 Rails 缺乏了解form for 我认为细分
  • Heroku Node.js node-http-proxy 模块没有此类应用程序错误

    我正在尝试将流量从测试应用程序的 api url 重定向到 Heroku 上托管的 api 因此 localhost api hello 应该代理到 testapp heroku com hello 并返回响应 使用 node http p
  • 初始化会破坏rails中的布局设置吗?

    在其中一个控制器中 我需要特定的布局 我添加了layout一开始 效果很好 但如果我添加一个initialize某些基于控制器的变量的函数 Rails 似乎只是忽略了layout命令 有人有同样的问题吗 我该如何修复它 class Admi
  • Rails 6 - 操作文本和 API

    我正在创建一个 Rails 6 0 0 应用程序 它具有以下模块 网络 表格 Cruds Api 我使用的地方有一个 CRUD动作文本 https edgeguides rubyonrails org action text overvie
  • MySQL 查询中的窗口函数

    有没有办法在 SELECT 查询本身中动态地使用 MySQL 查询中的窗口函数 我知道在 PostgreSQL 中这是可能的 例如 下面是 PostgreSQL 中的等效查询 SELECT c server ip c client ip s
  • Heroku 码头部署

    我正在关注这篇文章https devcenter heroku com articles container registry and runtime https devcenter heroku com articles containe
  • 如何在我的 heroku 应用程序上安装软件包?

    我有一个使用 Shortuuid 的应用程序 https pypi python org pypi shortuuid 0 1 https pypi python org pypi shortuuid 0 1 当我使用 runapp py

随机推荐