Forum: Ruby on Rails Inserting fixture data with a primary key of 0

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
95ece3bc20c5dc43685302703a1e99bd?d=identicon&s=25 Erik Hollensbe (erikh)
on 2009-05-25 12:15
This doesn't seem to work on mysql, at least. We depend on this
functionality as we're porting an old app over to rails; does anyone
know where I can find out how to disable the magic going on here?

For fixture a:

a:
  id: 0
  stuff: "stuff"

If 'id' is the primary key, it will be autoincremented upon each load,
so that the first load it will be '1', then '2', so on.

I want it to be '0'. :) Casting to string and other voodoo (such as ERB)
do not have any effect; the fixture code is obviously checking for '0'
and using the sequence instead.

Any pragmatic advice (yes, we desperately want to get rid of things like
this, but that's not pragmatic right now as the database has to run
against both platforms ATM) would be greatly appreciated. Thanks!

-Erik
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-25 12:48
(Received via mailing list)
On May 25, 11:15 am, Erik Hollensbe <rails-mailing-l...@andreas-s.net>
wrote:
> This doesn't seem to work on mysql, at least. We depend on this
> functionality as we're porting an old app over to rails; does anyone
> know where I can find out how to disable the magic going on here?
>

I don't think this isn't a rails thing (at least I can see anything in
the fixtures code for that). on the other hand, the mysql
documentation says:
http://dev.mysql.com/doc/refman/5.0/en/server-sql-...

>Normally, you generate the next sequence number for the column by inserting either NULL 
or 0 into it.
> NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the 
next sequence number.

Fred
95ece3bc20c5dc43685302703a1e99bd?d=identicon&s=25 Erik Hollensbe (erikh)
on 2009-05-25 20:33
Frederick Cheung wrote:
> On May 25, 11:15�am, Erik Hollensbe <rails-mailing-l...@andreas-s.net>
> wrote:
>> This doesn't seem to work on mysql, at least. We depend on this
>> functionality as we're porting an old app over to rails; does anyone
>> know where I can find out how to disable the magic going on here?
>>
>
> I don't think this isn't a rails thing (at least I can see anything in
> the fixtures code for that). on the other hand, the mysql
> documentation says:
> 
http://dev.mysql.com/doc/refman/5.0/en/server-sql-...
>
>>Normally, you generate the next sequence number for the column by inserting either NULL 
or 0 into it.
>> NO_AUTO_VALUE_ON_ZERO suppresses this behavior for 0 so that only NULL generates the 
next sequence number.
>
> Fred

Wow; nice catch. I guess my development environment differed from
production. Thanks so much!
This topic is locked and can not be replied to.