I''m trying to load some Rake Fixtures (rake db:fixtures:load) into a MySql database and I''m seeing some weird behaviour with AutoIncrement values. Normally this goes up by 1 for each insert which allows me to define/create tests. (BTW - normal create/insert from script works correctly). However when I load from fixtures the id field is assigned a large random number and the autoinc value on the table is also a large number (1054583385) after the load. Has anyone else seen this? FWIW this is on Windows XP with MySql 5.0 (I also tested with MySql 5.1, found the problem and rolled back to 5.0). Anybody else seen this - Is this a known bug/issue? TIA
Marnen Laibow-Koser
2009-Jul-31 22:36 UTC
Re: Rake db Fixtures MySql autoincrement problem?
BrendanC wrote:> I''m trying to load some Rake Fixtures (rake db:fixtures:load) into a > MySql database and I''m seeing some weird behaviour with AutoIncrement > values. Normally this goes up by 1 for each insert which allows me to > define/create tests. (BTW - normal create/insert from script works > correctly). > > However when I load from fixtures the id field is assigned a large > random number and the autoinc value on the table is also a large > number (1054583385) after the load. Has anyone else seen this?This is normal behavior (I believe the numbers come from a hash of the record, or something like that). Why is it a problem for you? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
killcap-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Aug-05 13:33 UTC
Re: Rake db Fixtures MySql autoincrement problem?
Just tried the same think and I was surprised as you. I do not think that it is normal behavior. It is really weird. And even sometimes it works as I wish and second time (after rake db:fixture:load) not. Zdenek On 1 srp, 00:36, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> BrendanC wrote: > > I''m trying to load some Rake Fixtures (rake db:fixtures:load) into a > > MySql database and I''m seeing some weird behaviour with AutoIncrement > > values. Normally this goes up by 1 for each insert which allows me to > > define/create tests. (BTW - normal create/insert from script works > > correctly). > > > However when I load from fixtures the id field is assigned a large > > random number and the autoinc value on the table is also a large > > number (1054583385) after the load. Has anyone else seen this? > > This is normal behavior (I believe the numbers come from a hash of the > record, or something like that). Why is it a problem for you? > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.
2009/8/5 killcap-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <killcap-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > Just tried the same think and I was surprised as you. I do not think > that it is normal behavior. > It is really weird. And even sometimes it works as I wish and second > time (after rake db:fixture:load) not.As Marnen said this is normal behaviour. If an id value is explicitly provided for a record in the fixture data then that value will be used, otherwise a value is calculated from the name of the record (ie the heading line of the record in the fixture). This allows automatic linking of associated record. So if A has_many Bs and B belongs_to A then in A fixture: a_1: field_1: data field_2: data and in B fixture b_1: a: a_1 # instead of a_id: id_of_a_1_whatever_that_is this makes it much easier to link records than manually setting up all the id values Colin> > Zdenek > > On 1 srp, 00:36, Marnen Laibow-Koser <rails-mailing-l...@andreas- > s.net> wrote: >> BrendanC wrote: >> > I''m trying to load some Rake Fixtures (rake db:fixtures:load) into a >> > MySql database and I''m seeing some weird behaviour with AutoIncrement >> > values. Normally this goes up by 1 for each insert which allows me to >> > define/create tests. (BTW - normal create/insert from script works >> > correctly). >> >> > However when I load from fixtures the id field is assigned a large >> > random number and the autoinc value on the table is also a large >> > number (1054583385) after the load. Has anyone else seen this? >> >> This is normal behavior (I believe the numbers come from a hash of the >> record, or something like that). Why is it a problem for you? >> >> Best, >> -- >> Marnen Laibow-Koserhttp://www.marnen.org >> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org >> -- >> Posted viahttp://www.ruby-forum.com/. > > >