it-swarm.com.de

PG :: DuplicateTable: ERROR

Wenn ich rake db: migrate ausführe, erhalte ich folgende Ausgabe:

== 20141219011612 CreatePost: Migration ======================================== - create_table (" posts ") Rechen abgebrochen! StandardError: Ein Fehler ist aufgetreten, diese und alle späteren Migrationen wurden abgebrochen: == 20141219011612 Postposts: migrating =============================== ========= - create_table ("posts") Rechen abgebrochen! StandardError: Ein Fehler ist aufgetreten, diese und alle späteren Migrationen wurden abgebrochen:

PG :: DuplicateTable: FEHLER: Beziehung "posts" existiert bereits: CREATE TABLE "posts" (Serienschlüssel "id", Text "post", Zeitstempel "release_date", Zeitstempel "created_at", Zeitstempel "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: 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' /home/admin/Desktop/postr/db/migrate/20141219011612_post_posts.rb:3:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:598:in exec_migration' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:579:in Block (2 Ebenen) in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:578:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in with_connection '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:577:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:752:in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:991:in block in execute_migration_in_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in Block in ddl_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in block in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in innerhalb_neuer_Transaktionen '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:intransaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in ddl_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:990:in execute_migration_in_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:952:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in each '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in Block (2 Ebenen) in 'ActiveRecord :: StatementInvalid: PG :: DuplicateTable: ERROR: Beziehung "posts" ist bereits vorhanden: CREATE TABLE "posts" (Serienschlüssel "id", Text "post", Zeitstempel "release_date") , "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' /home/admin/Desktop/postr/db/migrate/20141219011612_post_posts.rb:3:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:598:in exec_migration' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:579:in Block (2 Ebenen) in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:578:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in with_connection '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:577:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:752:in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:991:in block in execute_migration_in_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in Block in ddl_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in block in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in innerhalb_neuer_Transaktionen '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:intransaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in ddl_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:990:in execute_migration_in_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:952:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in each '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in Block (2 Ebenen) in 'PG :: DuplicateTable: ERROR: Beziehung "posts" existiert bereits /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' /home/admin/Desktop/postr/db/migrate/20141219011612_post_posts.rb:3:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:598:in exec_migration' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:579:in Block (2 Ebenen) in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:578:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in with_connection '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:577:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:752:in migrate '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:991:in block in execute_migration_in_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in Block in ddl_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in block in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in innerhalb_neuer_Transaktionen '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:intransaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:1037:in ddl_transaction' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:990:in execute_migration_in_transaction '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:952:in block in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in each '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:948:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in up '/home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in migrate' /home/admin/.rvm/gems/Ruby-2.1.5/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in block (2 Ebenen) in 'Tasks: TOP => db: migrate (Vollständige Ablaufverfolgung anzeigen, indem Task mit --trace ausgeführt wird)

Ich verstehe nicht, wie das möglich ist, weil ich in der Schemadatei keine Post-Tabelle habe.

18
Leag Er

Irgendwie haben Sie eine Tabelle mit dem Namen 'posts' in Ihrer Datenbank erhalten. Vielleicht von einer vorherigen Migration, die Sie ohne Zurücksetzen gelöscht haben? Wenn Sie sich nicht für irgendwelche Ihrer Daten in der Datenbank interessieren, können Sie sie ausführen

rake db:drop db:create db:migrate

um Ihre Entwicklungsdatenbank mit Ihren aktuellen Migrationen in Einklang zu bringen.

Wenn Sie Daten in anderen Tabellen haben, die Sie nicht verlieren möchten, öffnen Sie die Datenbankkonsole und löschen Sie die Posts-Tabelle manuell:

$ Rails db

# drop table posts;

Führen Sie dann erneut db:migrate aus. 

51
Bill Doughty

Einer der Hacks, den ich gefunden habe, war das Setzen von "pry", bevor Sie die Tabelle für die Migrationsdatei erstellen.

require 'pry'
binding.pry

create_table :your_table_name

und lass den Tisch fallen:

drop_table :your_table_name

Danach können Sie das drop_table Linie und es wird gut funktionieren!

0
Sandip Subedi

Für den Fall, dass dies anderen hilft, wurde mir klar, dass ich eine schema.rb -Datei verwendet habe, die während der Verwendung von MySQL generiert wurde. Nach dem Umstieg auf Postgres habe ich einfach vergessen, dass ich rake db:migrate ausführen müsste, bevor ich rake db:schema:load verwenden könnte.

0
Adam Grant

Überprüfen Sie Ihre Datenbank/Schema.rb

Wahrscheinlich wird dort dieselbe Tabelle zusätzlich zu einer Migration in db/migrate/[timestamp] your_migration erstellt

Sie können db/migrate/[timestamp] your_migration löschen, wenn es sich um ein Duplikat des im Schema gefundenen handelt und es funktionieren sollte.

0
djadam