Syntax error, unexpected ':', expecting kEND

My db:migrate code as generated by ROR refuses to run. I’m running MySQL
as the db, and think I have everything installed and configured
correctly. I’ve tried deletion of the colon, quoting with single and
double quotes, and nothing seems to work, I just keep getting different
syntax errors. I’m new to ROR, but had a similar version working on a
different machine with a Debian install, and this is on gOS, an Ubuntu
derivative (it pretty much sucks(give me something that isn’t broken by
design.)) Code and a trace are copied below. Does anybody know how to
solve this?

001_create_cars.rb:

class CreateCars < ActiveRecord::Migration
def self.up
create_table :cars do |t|
t.varchar(64) :Title
t.varchar(255) :Img
t.varchar(64) :Maker
t.varchar(64) :Year
t.text :Desc
t.varchar(64) :Price
t.boolean :Show
t.boolean :Sold

  t.timestamps : ID
end

end

def self.down
drop_table :cars
end
end

rake db:migrate --trace
(in /usr/local/aptana/workspace/CarSales)
rake db:migrate
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
./db/migrate//001_create_cars.rb:4: syntax error, unexpected ‘:’,
expecting kEND
t.varchar(64) :Title
^
./db/migrate//001_create_cars.rb:5: syntax error, unexpected ‘:’,
expecting kEND
t.varchar(255) :Img
^
./db/migrate//001_create_cars.rb:6: syntax error, unexpected ‘:’,
expecting kEND
t.varchar(64) :Maker
^
./db/migrate//001_create_cars.rb:7: syntax error, unexpected ‘:’,
expecting kEND
t.varchar(64) :Year
^
./db/migrate//001_create_cars.rb:9: syntax error, unexpected ‘:’,
expecting kEND
t.varchar(64) :Price
^
/var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in
load' /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
/var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in
new_constants_in' /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:inload’
/var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:360:in
migration_classes' /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/mysql_adapter.rb:286:ininject’
/var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:359:in
each' /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:359:ininject’
/var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:359:in
migration_classes' /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:339:inmigrate’
/var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:307:in
up' /var/lib/gems/1.8/gems/activerecord-2.0.2/lib/active_record/migration.rb:298:inmigrate’
/var/lib/gems/1.8/gems/rails-2.0.2/lib/tasks/databases.rake:85
/usr/lib/ruby/1.8/rake.rb:387:in call' /usr/lib/ruby/1.8/rake.rb:387:inexecute’
/usr/lib/ruby/1.8/rake.rb:387:in each' /usr/lib/ruby/1.8/rake.rb:387:inexecute’
/usr/lib/ruby/1.8/rake.rb:357:in invoke' /usr/lib/ruby/1.8/rake.rb:350:insynchronize’
/usr/lib/ruby/1.8/rake.rb:350:in invoke' /usr/lib/ruby/1.8/rake.rb:1924:inrun’
/usr/lib/ruby/1.8/rake.rb:1924:in each' /usr/lib/ruby/1.8/rake.rb:1924:inrun’
/usr/bin/rake:4

With this syntax I think you’re passing ‘64’ as the only parameter:

t.varchar(64) :Title

Here’s how I’m used to seeing it:

t.string :title, :limit => 64

-Mack

On Wed, Apr 23, 2008 at 12:50 PM, Charles Hernandez

Mack Earnhardt wrote:

With this syntax I think you’re passing ‘64’ as the only parameter:

t.varchar(64) :Title

Here’s how I’m used to seeing it:

t.string :title, :limit => 64

-Mack

On Wed, Apr 23, 2008 at 12:50 PM, Charles Hernandez

Hi Mack,
Thanks for the quick response, the ‘64’ is to tell mysql how long to
make the field. The same code worked (at least I seem to remember it
being the same form “t.fieldtype(size) :Fieldname”) worked previously. I
just can’t figure out what the problem is with the colon placement, and
I really don’t know what the ‘kEND’ is supposed to be. Since the
generator created the code, you’d kind of expect it to run. :S

Charles Hernandez wrote:

Mack Earnhardt wrote:

With this syntax I think you’re passing ‘64’ as the only parameter:

t.varchar(64) :Title

Here’s how I’m used to seeing it:

t.string :title, :limit => 64

-Mack

On Wed, Apr 23, 2008 at 12:50 PM, Charles Hernandez

Hi Mack,
Thanks for the quick response, the ‘64’ is to tell mysql how long to
make the field. The same code worked (at least I seem to remember it
being the same form “t.fieldtype(size) :Fieldname”) worked previously. I
just can’t figure out what the problem is with the colon placement, and
I really don’t know what the ‘kEND’ is supposed to be. Since the
generator created the code, you’d kind of expect it to run. :S

Correct style is
t.string :title, :limit =>64

Your mixing how you do it in MySQL, with how you do it in Rails.

Charles Hernandez wrote:

Duh, I figured it out, I was remembering the datatypes in the DB itself.
Defective brain, sorry to have taken your time.

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