Migrate error

i have problem with ‘rake db:migrate’

i use this tutorial =>

form first step to this step.

when i type ‘rake db:migrate’ in my terminal.

i get this error =>

== 20160127215334 Books: migrating

– create_table(:books)
rake aborted!
StandardError: An error has occurred, this and all later migrations
canceled:

PG::DuplicateTable: ERROR: relation “books” already exists
: CREATE TABLE “books” (“id” serial primary key, “title” character
varying(32) NOT NULL, “price” float, “subject_id” integer, “description”
text, “created_at” timestamp)
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in
async_exec' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in block in execute’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in
block in log' /var/lib/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in instrument’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in
log' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in execute’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in
create_table' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in block in method_missing’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in
block in say_with_time' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in say_with_time’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in
method_missing' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in method_missing’
/root/Desktop/Rails/library/db/migrate/20160127215334_books.rb:4:in up' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in up’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in
exec_migration' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in block (2 levels) in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in
block in migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in with_connection’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in
block in execute_migration_in_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in block in ddl_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
block in transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in within_new_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in
ddl_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in execute_migration_in_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in
block in migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in each’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in up’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in
block (2 levels) in <top (required)>' ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "books" already exists : CREATE TABLE "books" ("id" serial primary key, "title" character varying(32) NOT NULL, "price" float, "subject_id" integer, "description" text, "created_at" timestamp) /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in async_exec’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in
block in execute' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in block in log’
/var/lib/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in
instrument' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in log’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in
execute' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in create_table’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in
block in method_missing' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in block in say_with_time’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in
say_with_time' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in method_missing’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in
method_missing' /root/Desktop/Rails/library/db/migrate/20160127215334_books.rb:4:in up’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in
up' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in exec_migration’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in
block (2 levels) in migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in block in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in
with_connection' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in block in execute_migration_in_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in
block in ddl_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in block in transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in
within_new_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in
transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in ddl_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in
execute_migration_in_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in block in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in
each' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in
up' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in block (2 levels) in <top (required)>’
PG::DuplicateTable: ERROR: relation “books” already exists
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in
async_exec' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in block in execute’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in
block in log' /var/lib/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in instrument’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in
log' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in execute’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:208:in
create_table' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:665:in block in method_missing’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in
block in say_with_time' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in say_with_time’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in
method_missing' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in method_missing’
/root/Desktop/Rails/library/db/migrate/20160127215334_books.rb:4:in up' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:571:in up’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:611:in
exec_migration' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:592:in block (2 levels) in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:591:in
block in migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in with_connection’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:590:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:998:in
block in execute_migration_in_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in block in ddl_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
block in transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in within_new_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in
transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1044:in
ddl_transaction' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:997:in execute_migration_in_transaction’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:959:in
block in migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in each’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in up’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in
migrate' /var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in migrate’
/var/lib/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in
`block (2 levels) in <top (required)>’
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

what i have to do now?

On 27 January 2016 at 13:32, Benyamin Pm [email protected] wrote:

text, “created_at” timestamp)
The error indicates that the migration calls for the creation of the
books table, but that table already exists.

Colin

Colin L. wrote in post #1180957:

On 27 January 2016 at 13:32, Benyamin Pm [email protected] wrote:

text, “created_at” timestamp)
The error indicates that the migration calls for the creation of the
books table, but that table already exists.

Colin

but i don’t create any table called ‘books’ for second time!

can u take a look at the models in turorial?
i see some mistakes in steps. maybe it have a problem in codes or
somthing like that

On 27 January 2016 at 14:28, Benyamin Pm [email protected] wrote:

but i don’t create any table called ‘books’ for second time!

can u take a look at the models in turorial?
i see some mistakes in steps. maybe it have a problem in codes or
somthing

Examine the database using whatever utility you use for doing that ( I
think it is psql for postgres, I guess there are also graphical
utilities) and I suspect you will find you have. Perhaps you have
accidentally added two migrations for adding the table, or perhaps you
have managed to run the migration twice. If you have nothing of
interest in the db than you can throw it away and start again using

rake db:drop # delete the db
rake db:create # create an empty one
rake db:migrate # run the migrations

Colin