Run this in rails terminal -
rails g migration remove_id_from_scaffoldname id:integer
rails g migration add_rowid_to_scaffoldname rowid:integer
This will create two migration files - one to remove id
field and the other to add the rowid
field.
Then run this in rails terminal -
rake db:migrate
Also note that rails will create id
field automatically but not the rowid
as your primary key. To restrict rails to use your defined primary key you have to define so explicitly like this here -
Your Migration file -
create_table :tablename, :primary_key => :rowid do |t|
# ...
end
Your Model -
class ModelName< ActiveRecord::Base
self.primary_key = "rowid"
...
end
Note: It is a good practice to use rails auto generated id
as a primary key unless otherwise you have a valid reason to do so.