Migration DB Question

Just going through ‘agile web development with rails’ 2nd ed.

I accidentally created an empty migration source file with the wrong
name,
ruby script/generate migration add_test_date

and then straight after that created the one I wanted to use
ruby script/generate migration add_test_data

and populated the second one - when I ran
rake db:migrate

a few times it did not seem to update the table. I read something in the
book about creating empty migration files, but I thought if I created a
new one it should work.

what should i do now? also - do i need the server running to perform
migrations?

cheers.

Hi Frank,

answers inline:

On 8/1/06, Frank M. [email protected] wrote:

Just going through ‘agile web development with rails’ 2nd ed.

I accidentally created an empty migration source file with the wrong
name,
ruby script/generate migration add_test_date

You might want to try ruby script/destroy migration add_test_date

and then straight after that created the one I wanted to use

ruby script/generate migration add_test_data

and populated the second one - when I ran
rake db:migrate

a few times it did not seem to update the table. I read something in the
book about creating empty migration files, but I thought if I created a
new one it should work.

Yes, I think so too. What exactly is it that is not working?

what should i do now? also - do i need the server running to perform

migrations?

No, that isn’t necessary.

cheers.

Cheers,
Jan

Thanks, I was able to delete the add_test_date fine. So I have:

db/migrate/001_create_products.rb
db/migrate/002_add_price.rb
db/migrate/add_test_data.rb

ran
rake db:migrate

only output was
(in C:rubyonrails/work/depot)

No change to the database, and the schema_info table has version 4 in
it.

here is the basic file i am trying to use:

class AddTestData < ActiveRecord::Migration
def self.up

Product.create(:title => 'Pragmatic Project Automation',
:description =>
%{<p>
   <em>Pragmatic Project Automation</em> shows you how to improve 

the
consistency and repeatability of your project’s procedures using
automation to reduce risk and errors.



Simply put, we’re going to put this thing called a computer to
work
for you doing the mundane (but important) project stuff. That
means
you’ll have more time and energy to do the really
exciting—and difficult—stuff, like writing quality code.

},
:image_url => ‘/images/auto.jpg’,
:price => 29.95)

end

def self.down
Product.delete_all
end
end

I don’t really know how or where it is supposed to get Product.create
from?

cheers

Jan P. wrote:

Hi Frank,

answers inline:

On 8/1/06, Frank M. [email protected] wrote:

Just going through ‘agile web development with rails’ 2nd ed.

I accidentally created an empty migration source file with the wrong
name,
ruby script/generate migration add_test_date

You might want to try ruby script/destroy migration add_test_date

and then straight after that created the one I wanted to use

ruby script/generate migration add_test_data

and populated the second one - when I ran
rake db:migrate

a few times it did not seem to update the table. I read something in the
book about creating empty migration files, but I thought if I created a
new one it should work.

Yes, I think so too. What exactly is it that is not working?

what should i do now? also - do i need the server running to perform

migrations?

No, that isn’t necessary.

cheers.

Cheers,
Jan

**Sorry - I found where the create() method is for product.

Umm, it should be 003, but i made a typo and created 003_add_test_date.

so in fact i made another typo below (my night for typos)…it is
actually…

db/migrate/004_add_test_data.rb

Thanks,
Frank.

Tom W. wrote:

On 01/08/06, Frank M. [email protected] wrote:

Thanks, I was able to delete the add_test_date fine. So I have:

db/migrate/001_create_products.rb
db/migrate/002_add_price.rb
db/migrate/add_test_data.rb

Should the final file not be:

db/migrate/003_add_test_data.rb

Tom

Hi Frank,

ok, if the schema_info table corresponds to 004_… as the last file in
the
rake filename scheme, then it’s no wonder that no migrations are issued
because the migration ‘assumes’ that migration files and database are in
sync.

IMHO you need to set back the schema_info to ‘3’ either by running rake
migrate VERSION=3 or by issuing update schema_info set version = 3; on
the
sql command line. After that run rake db:migrate once again.

Cheers,
Jan

Hi Jan,

thanks very much - thats helped me a lot. i was able to set the version
to 0 or 3 or whatever and it changed the database accordingly. but
still, when i ran rake db:migrate or rake db:migrate VERSION=4 the
database did not get populated as I thought it would…

I even changed the file to be 003_add_test_data.rb (for continuity
001,002,003…), the structure of db stays as I guess it was created in
001 and 002, but the data in 003 does not get entered.

are there any log files i can check?

thanks again,
Frank.

Jan P. wrote:

Hi Frank,

ok, if the schema_info table corresponds to 004_… as the last file in
the
rake filename scheme, then it’s no wonder that no migrations are issued
because the migration ‘assumes’ that migration files and database are in
sync.

IMHO you need to set back the schema_info to ‘3’ either by running rake
migrate VERSION=3 or by issuing update schema_info set version = 3; on
the
sql command line. After that run rake db:migrate once again.

Cheers,
Jan

On 01/08/06, Frank M. [email protected] wrote:

Thanks, I was able to delete the add_test_date fine. So I have:

db/migrate/001_create_products.rb
db/migrate/002_add_price.rb
db/migrate/add_test_data.rb

Should the final file not be:

db/migrate/003_add_test_data.rb

Tom

Hi,

Sorry I had to quit last night as it was getting late. Here is the only
relevant stuff in the log I think…

e[4;36;1mSQL (0.000000)e[0m e[0;1mMysql::Error: Table ‘schema_info’
already exists: CREATE TABLE schema_info (version int(11))e[0m
e[4;35;1mSQL (0.000000)e[0m e[0mMysql::Error: Table ‘schema_info’
already exists: CREATE TABLE schema_info (version int(11))e[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mSELECT version FROM
schema_infoe[0m
e[4;35;1mSQL (0.000000)e[0m e[0mSELECT version FROM schema_infoe[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mSELECT version FROM
schema_infoe[0m
e[4;35;1mSQL (0.000000)e[0m e[0mSELECT * FROM schema_infoe[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mSHOW TABLESe[0m
e[4;35;1mSQL (0.016000)e[0m e[0mSHOW FIELDS FROM productse[0m
e[4;36;1mSQL (0.000000)e[0m e[0;1mSHOW KEYS FROM productse[0m

I doesn’t really like running the Product.create command. With no
arguments it gives validation errors which makes sense, but with all the
correct values it just goes onto the next line of the prompt without
putting info in db?

Jan P. wrote:

Is there anything in your development.log according to the migration?

Are you able to issue the Product.create … on the console via
RAILS_ROOT>ruby script/console?

Cheers,
Jan

On 8/2/06, Frank M. [email protected] wrote:

e[4;36;1mSQL (0.000000)e[0m e[0;1mSELECT version FROM
arguments it gives validation errors which makes sense, but with all the
correct values it just goes onto the next line of the prompt without
putting info in db?

Ok if I understand this right than you had no luck in creating products
on
the command line either? Than you need to find your problem there. Why
isn’t
ActiveRecord working? There’s got to be a problem with your model.
Doesn’t
your log tell you something about this. What’s with a simple scaffolding
‘new’ of the Product. Does this work?

Your migration won’t have any effect on the database as long as your
Product.create command won’t have any effect on the db either…

Cheers,
Jan

Is there anything in your development.log according to the migration?

Are you able to issue the Product.create … on the console via
RAILS_ROOT>ruby script/console?

Cheers,
Jan

I had a similar problem–no typos but running “rake db:migrate” didn’t
seem to populate any data.

Try running rake db:migrate VERSION=4

That worked for me and populated all the data.

-Toby

Frank M. wrote:

Hi Jan,

thanks very much - thats helped me a lot. i was able to set the version
to 0 or 3 or whatever and it changed the database accordingly. but
still, when i ran rake db:migrate or rake db:migrate VERSION=4 the
database did not get populated as I thought it would…

I even changed the file to be 003_add_test_data.rb (for continuity
001,002,003…), the structure of db stays as I guess it was created in
001 and 002, but the data in 003 does not get entered.

are there any log files i can check?

thanks again,
Frank.

Jan P. wrote:

Hi Frank,

ok, if the schema_info table corresponds to 004_… as the last file in
the
rake filename scheme, then it’s no wonder that no migrations are issued
because the migration ‘assumes’ that migration files and database are in
sync.

IMHO you need to set back the schema_info to ‘3’ either by running rake
migrate VERSION=3 or by issuing update schema_info set version = 3; on
the
sql command line. After that run rake db:migrate once again.

Cheers,
Jan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs