Slinky
Slinky

Reputation: 5832

Rails 3 - ActiveRecord::StatementInvalid

I migrated a Rails 2.2.2 site over to Rails 3.1. The schema is identical but now I get an ActiveRecord error when the model calls save() on a partial INSERT.

This is causing a constraint issue, which really isn't because the column is auto-incrementing in PostGres, thus it will never be NULL.

Rails is all conventions and I thought it assumes 'id' column to be the primary key.

What's the best way to handle this?

1) Remove the "NOT NULL" from the schema column definition

2) Some way from inside Rails 3 to tell ActiveRecord.save() to ignore this constraint since it's an auto-increment field?

Thanks!

Upvotes: 0

Views: 87

Answers (1)

Slinky
Slinky

Reputation: 5832

In your model do this:

self.primary_key = "your PK column name"

Upvotes: 1

Related Questions