简体   繁体   中英

Rails: after using scaffold, I can't migrate

[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"

  1. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM