# Inserting fixture data with a primary key of 0

**URL:** <https://www.ruby-forum.com/t/inserting-fixture-data-with-a-primary-key-of-0/168747>\
**Category:** Rails\
**Created:** [May 25, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/inserting-fixture-data-with-a-primary-key-of-0/168747 "2009-05-25T12:15:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![happolati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/51bf81/32.png) [@happolati](https://www.ruby-forum.com/u/happolati)\
**Post date:** [May 25, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/inserting-fixture-data-with-a-primary-key-of-0/168747/1 "2009-05-25T12:15:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![happolati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/51bf81/32.png) [@happolati](https://www.ruby-forum.com/u/happolati)\
**Post date:** [May 25, 2009, 12:48pm UTC](https://www.ruby-forum.com/t/inserting-fixture-data-with-a-primary-key-of-0/168747/2 "2009-05-25T12:48:58Z")

</div>

On May 25, 11:15 am, Erik H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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-mode.html#sqlmode\_no\_auto\_value\_on\_zero](http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_no_auto_value_on_zero)

> 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

---

<div class="post-metadata">

**Author:** ![happolati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/51bf81/32.png) [@happolati](https://www.ruby-forum.com/u/happolati)\
**Post date:** [May 25, 2009, 8:33pm UTC](https://www.ruby-forum.com/t/inserting-fixture-data-with-a-primary-key-of-0/168747/3 "2009-05-25T20:33:39Z")

</div>

Frederick C. wrote:

> On May 25, 11:15ï¿½am, Erik H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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-mode.html#sqlmode\_no\_auto\_value\_on\_zero](http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_no_auto_value_on_zero)
> 
> > 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!
