Reputation: 213
Everytimes, I have a column for my event object (event-calendar gem) in my schema.rb file
t.integer "id", :null => false
So of course, every time I want to create an event I have an error "null value in column "id" violates not-null constraint" because of this. I tried this solution ActiveRecord::StatementInvalid: PG::Error: ERROR: null value in column "id" violates not-null constraint but it appears everytimes !!! I would like to know WHY this column appears here, I really don't understand...
Any idea ?
Upvotes: 2
Views: 723
Reputation: 2666
When you created the events model, it sounds like you added an id field. This isn't necessary as rails automatically creates this field. Your event model in your schema should look something like:
create_table "events", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
I would rollback the migration, assuming this is the most recent migration:
rake db:rollback
Then update the migration file and remove the id from the create_table block:
class CreateEvents < ActiveRecord::Migration
def change
create_table :events do |t|
t.string :name
t.timestamps
end
end
end
Then rerun the migration.
Upvotes: 2