Reputation: 4368
In my rails app I have a model Events
. It has several columns which were created through following this guide https://devcenter.heroku.com/articles/export-from-heroku-postgres and then performing rake db:schema:dump
.
Now I want to add some new columns to the Event
model. I tried editing schema.rb
and restarting the app but that didn't seem to work. Anyone know the proper way to proceed?
----Edit-------
Specifically I added this line to the Event
model in schema.rb
.
t.datetime "date_time"
When I click the link to add a event in the rails app I receive this error:
undefined method `date_time' for #<Event:0x007fdb59a87118>
Upvotes: 1
Views: 1283
Reputation: 434685
The schema.rb
file is a representation of the current state of the database schema, it is written by the database migration process, not read.
If you want to add a new column, create a migration:
$ rails generate migration AddNewEventStuff
$ vim db/migrate/add_new_event_stuff*.rb
Then add your columns:
class AddNewEventStuff < ActiveRecord::Migration
def change
add_column ...
end
end
Everything except the add_column
should be there already. Once you have your migration, do a rake db:migrate
and you're done. Now you should see some changes in your schema.rb
.
See the Ruby on Rails Migration Guide for further details and different ways to build your migrations.
Upvotes: 2
Reputation: 9691
You should try heroku run rake db:schema:load
. That said, it's probably the wrong way to go about. Instead, you should make changes to your schema via migrations, and then run a heroku run rake db:migrate
on it.
Upvotes: 0