sql - First active_record insert id is set to NULL automatically -
sql - First active_record insert id is set to NULL automatically -
i have schema:
create_table :tweets, id: false |t| # we'll utilize id store actual tweet id t.integer :id, null: false t.string :text t.datetime :created_at t.index :created_at end class tweet < activerecord::base end
i'm trying utilize active_record, provide own id
values on each insert.
now when seek insert same thing twice, error first time, works after that:
> tweet.create(id: 123, text: 'foo', created_at: time.now)) activerecord::statementinvalid: pg::notnullviolation: error : null value in column "id" violates not-null constraint detail: failing row contains (null, foo, 2014-10-06 15:45:46.149613). : insert "tweets" ("created_at", "text") values ($1, $2) /home/mapleoin/tweetwatch/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.6/l ib/active_record/connection_adapters/postgresql_adapter.rb:834:in `get_last_result' > tweet.create(id: 123, text: 'foo', created_at: time.now)) => #<tweet id: 123, text: "foo", created_at: "2014-10-06 17:45:57">
using postgresql pg
gem active_record 4.1.6
so why first insert differetn?
sql ruby activerecord
Comments
Post a Comment