Rails Migrations not working properly?

16 views
Skip to first unread message

Christopher Saunders

unread,
Jan 6, 2010, 10:53:38 AM1/6/10
to ogre...@googlegroups.com
Hello,

I am trying to do some rails development using sqlite3 and am having some issues with my migrations.  When I run the "rake db:migrate" task all my tables get created but they are only getting populated with the default rows.

For example:
    create_table :users do |t|
      t.login :string
      t.password :string
      t.email :string

      t.timestamps
    end

If I look at the contents of the users table in sqlite I get the following:
sqlite> .dump users
BEGIN TRANSACTION;
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime);
COMMIT;

This is the first time I've ever run into this problem.
I am using rails 2.3.4 and sqlite3-ruby 1.2.5

Thanks,
--
Christopher Saunders
Linux and Open Source Enthusiast
blog.christophersaunders.ca

Michael Richardson

unread,
Jan 6, 2010, 11:01:30 AM1/6/10
to ogre...@googlegroups.com

>>>>> "Christopher" == Christopher Saunders <c.saun...@gmail.com> writes:
Christopher> I am trying to do some rails development using sqlite3
Christopher> and am having some issues with my migrations. When I
Christopher> run the "rake db:migrate" task all my tables get
Christopher> created but they are only getting populated with the
Christopher> default rows.

Christopher> For example:
Christopher> create_table :users do |t|
Christopher> t.login :string
Christopher> t.password :string
Christopher> t.email :string

The syntax is:
t.column :login, :string
t.column :password, :string
t.column :email, :string

If the create_table now does some kind method missing handling, it's
new to me :-)

--
] He who is tired of Weird Al is tired of life! | firewalls [
] Michael Richardson, Sandelman Software Works, Ottawa, ON |net architect[
] m...@sandelman.ottawa.on.ca http://www.sandelman.ottawa.on.ca/ |device driver[
Kyoto Plus: watch the video <http://www.youtube.com/watch?v=kzx1ycLXQSE>
then sign the petition.

Edward Ocampo-Gooding

unread,
Jan 6, 2010, 11:01:25 AM1/6/10
to ogre...@googlegroups.com
Hey Chris,

I make this mistake once in a while too: make sure the order is

t.database_type :column_name

so your migration looks like this instead:

create_table :users do |t|
t.string :login
t.string :password
t.string :email

t.timestamps
end

It's a little weird that ActiveRecord didn't throw an exception complaining about not being able to create a column with type 'login'. Maybe when using MySQL you do get that, and because most users are on MySQL, not enough people have complained/cared about the issue/written a patch.

See if you get the same silent fail on MySQL and if so, it sounds like a patch is in order.

> --
> You received this message because you are subscribed to the Ottawa Group of Ruby Enthusiasts [OGRE].
> To post to this group, send email to ogre...@googlegroups.com
> To unsubscribe from this group, send email to
> ogre-list+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ogre-list?hl=en

Christopher Saunders

unread,
Jan 6, 2010, 11:21:25 AM1/6/10
to ogre...@googlegroups.com
That is very odd because I used the script/generator to make all my my migrations.

Perhaps these are the "issues" someone on the rails IRC might have been talking about.

Cody Fauser

unread,
Jan 6, 2010, 7:22:02 PM1/6/10
to ogre...@googlegroups.com
You can also generate them backwards with the generator like:

> script/generate Order string:name

Instead of

> script/generate Order name:string

--
Cody Fauser
http://shopify.com - e-commerce done right
http://www.codyfauser.com - blog
http://peepcode.com/products/activemerchant-pdf - ActiveMerchant PeepCode
http://www.oreilly.com/catalog/rjsrails - RJS Templates for Rails

Reply all
Reply to author
Forward
0 new messages