Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)
От | Russ Brown |
---|---|
Тема | Re: PostgreSQL primary (sequence) key issue (Ruby/Rails) |
Дата | |
Msg-id | 45E72EC2.2020702@gmail.com обсуждение исходный текст |
Ответ на | Re: PostgreSQL primary (sequence) key issue (Ruby/Rails) ("Joshua D. Drake" <jd@commandprompt.com>) |
Ответы |
Re: PostgreSQL primary (sequence) key issue (Ruby/Rails)
|
Список | pgsql-general |
Joshua D. Drake wrote: >> On 01/03/07, Andrew Madu < andrewmadu@gmail.com> wrote: >>> Hi Dave, >>> my apologies for contacting you off list but i'm having a spot of bother >>> with postgreSQL sequence setup in rails. In addition to what is mentioned >>> below, I have place the following line of code in my > > The definition of primary key explicitly states that it can't be null. > You are trying to pass a null to user_id which won't work. > > Joshua D. Drkae > In MySQL that is traditionally how you tell the RDBMS to use the auto_increment to generate the value. Postgres correctly doesn't allow that (since you might actually try to set a field to NULL accidentally in which case an error is expected). The portable (and correct) way to do it is to use the DEFAULT keyword like this: INSERT INTO some_table (id_field) VALUES (DEFAULT); I just tested on MySQL 5.0.32 and that syntax works fine. -- Russ.
В списке pgsql-general по дате отправления: