reset password
Author Message
msargent
Posts: 519
Posted 15:15 Feb 03, 2015 |

I was trying to insert a row into this table that was generated in part 1 of HW3:

create table Plan (
    id int4 not null,
    primary key (id)
);

I tried googling, and got these suggestions:

insert into Plan default values;

insert into Plan (id) values (null);

but got "null value in column "id" violates not-null constraint" Any ideas?

Last edited by msargent at 15:16 Feb 03, 2015.
toramoss
Posts: 13
Posted 15:27 Feb 03, 2015 |

When you create a table, the primary key usually has a constraint for it to be not null. This means that when you try to add a record, you must specify at least the id in Plan.

insert into Plan(id) values(null); would not be allowed, but insert into Plan(id) values(1); should work.

cysun
Posts: 2935
Posted 15:35 Feb 03, 2015 |

insert into Plan (id) values (nextval('hibernate_sequence'))

Or better yet, just add more fields. A plan could have a name field to make it easier to distinguish between different versions/revisions, e.g. "GEFP for Computer Science v1.1", "GEFP for Computer Science (Quarter)", "GEFP for Computer Science (Semester)". It would also make sense to add fields like creator, createDate, publishDate, completed, deleted, and so on.