Topic: AR Migrations and Model default values

Could some body tell me why when I try to insert a record with a model in a migration, that AR tries to specify values for fields that I haven't specified in the code. I've tried several different methods of AR record creation to no avail.  It's trying to specify values for columns that are auto incremented by default. Here's an example of some code:

        pset =  PermissionSet.new
        pset.owner_user_rtid = 10
        pset.owner_record_rtid = 1
        pset.owner_graph_rtid = t.rtid
        pset.owner_permission_set_rtid = 1
        pset.creator_rtid = 10
        pset.created_at = 'now()'
        pset.updater_rtid = 10
        pset.updated_at = 'now()'
        pset.label = r

        pset.save!


And yet when this runs the statement comes out like this:

INSERT INTO "projects" ("rtid", "vtid", "owner_user_rtid", "owner_record_rtid", "owner_graph_rtid", "owner_permission_set_rtid", "creator_rtid", "created_at", "updater_rtid", "updated_at", "label", "logo", "website", "old_nid", "old_id", "public_license_id", "public") VALUES (NULL, NULL, 10, 1, 1, 1, 10, '2012-07-11 14:04:46.126260', 10, '2012-07-11 14:04:46.126260', 'Project Namey', NULL, NULL, NULL, NULL, 1, NULL) RETURNING "project_id"

See how it specifies rtid and vtid which I did not set. These fields are set to NOT NULL in the DB which I suppose might be why it's trying to enforce it. I don't understand why it wont let the default value for these fields run which would be something like  nextval(pgsql_sequence). It does respect the project_id field which is the primary key. It seems strange that it would enforce the NOT NULL rule with out respecting the default value.

Thanks for any insight,
-G

Last edited by gete76 (2012-07-11 14:31:26)

Re: AR Migrations and Model default values

I'm assuming this is just functionality I've never had to question before because it's rare to have multiple auto incremented values on the same table.