[rails 4.1.6, ruby 2.1.3p242 ]
1.set the database.yml database: bookshop
, and created the bookshop
database in my database.
2.create a new table books
with id int(10), name varchar(45)
by SQL( I use MySQL).
3.everything is Okay, I can open the project in the browser.
things became a little weird after I typed rails g scaffold Book id:integer name:string
, which worked successfully.
But, as I restart the rails project, then the browser came out
"Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development"
bin/rake db:migrate RAILS_ENV=development
it shows == 20141003105907 CreateBooks: migrating ====================================== -- create_table(:books) rake aborted! StandardError: An error has occurred, all later migrations canceled:
you can't redefine the primary key column 'id'. To define a custom primary key, pass { id: false } to create_table./usr/local/...
ID fields are added to models by default - you don't need to add them yourself.
Destroy the scaffold you made, with rails destroy scaffold Book
, and create it again - this time without the id:integer
field.