PG::DuplicateTable:错误:关系“帖子";已经存在 [英] PG::DuplicateTable: ERROR: relation "posts" already exists

查看:169
本文介绍了PG::DuplicateTable:错误:关系“帖子";已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 rake db:migrate 时,我得到以下输出:

When I run rake db:migrate I get following output:

== 20141219011612 CreatePost:迁移 ==========================================================================================================================================================================================================================================================================================================================================================================-- create_table("posts") rake 中止!标准错误:发生错误,这次和所有以后的迁移都取消了:== 20141219011612 帖子:迁移 ====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================-- create_table("posts") rake 中止!标准错误:发生错误,这次和所有以后的迁移都取消了:

== 20141219011612 CreatePost: migrating ======================================= -- create_table("posts") rake aborted! StandardError: An error has occurred, this and all later migrations canceled: == 20141219011612 Postposts: migrating ======================================= -- create_table("posts") rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

PG::DuplicateTable:错误:关系帖子";已经存在:创建表格帖子"(id"串行主键,post"文本,release_date";时间戳,created_at";时间戳,updated_at";时间戳)/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:inasync_exec'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in 阻止执行'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in block in log'/home/admin/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in instrument'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:367:in log'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in execute'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:increate_table'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:649:in block in method_missing'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in阻止say_with_time'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in say_with_time'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:641:in`method_missing'

PG::DuplicateTable: ERROR: relation "posts" already exists : CREATE TABLE "posts" ("id" serial primary key, "post" text, "release_date" timestamp, "created_at" timestamp, "updated_at" timestamp) /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in async_exec' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in block in execute' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in block in log' /home/admin/.rvm/gems/ruby-2.1.5/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in instrument' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:367:in log' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in execute' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:205:in create_table' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:649:in block in method_missing' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in block in say_with_time' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in say_with_time' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:641:in `method_missing'

...

migrate'/home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in block(2 个级别) 在 <top (required)>'任务:TOP =>db:migrate(见通过使用 --trace 运行任务进行完整跟踪)

migrate' /home/admin/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.8/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)

我不明白这是怎么可能的,因为在方案文件中我没有发布表.

I don't understund how this is possible, bescause In scheme file I don't have post table.

推荐答案

不知何故,您最终在数据库中生成了一个名为posts"的表.也许是从您之前删除的迁移中删除而没有回滚?如果你不关心数据库中的任何数据,你可以运行

Somehow, you ended up with a table named 'posts' in your database. Perhaps from a prior migration that you deleted without rolling back? If you don't care about any of your data in the database, you can run

rake db:drop db:create db:migrate

使您的开发数据库与您当前的迁移保持一致.

to bring your development database inline with your current migrations.

如果您不想丢失其他表中的数据,请打开数据库控制台并手动删除posts表:

If you have data in other tables you don't want to lose, open the database console and drop the posts table manually:

$ rails db

# drop table posts;

然后再次运行db:migrate.

这篇关于PG::DuplicateTable:错误:关系“帖子";已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆