Reputation: 3960
First I ran: rails generate model User name:string email:string
and this create a migration. Later I did a db:migrate
and I get this error:
bundle exec rake db:migrate
== 20150728195629 CreateUsers: migrating ======================================
-- create_table(:users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "users" already exists.....
When you generate model
the table user
is created but then when you rake db:migrate
it tries to create it again.
I'm confused! Am I doing something wrong?
https://www.railstutorial.org/book/modeling_users#code-generate_user_model
Upvotes: 0
Views: 3085
Reputation: 1
just run into the console
rails db:reset
just run into the console
bundle exec rails db:migrate
Upvotes: 0
Reputation: 321
just run into the console
rails console
and type in
ActiveRecord::Migration.drop_table(:users)
and then exit the console and
rake db:migrate
Upvotes: 11
Reputation: 4561
You must have created a table as Marsatomic said. Run
bundle exec rake db:migrate:status
And look at your migration history to see where you created it. If you see it, you can roll back your migrations past that table, delete the migration file that created it, and then re-run your migrations. If you don't see it anywhere, you must have created the table without a migration. At that point you should do as Marsatomic instructed in his comment above.
Upvotes: 3